python
2024-11-06 13:40:50 0 举报
AI智能生成
图
作者其他创作
大纲/内容
作图
图1:折线图
import matplotlib.pyplot as plt<br>plt.rcParams["font.sans-serif"]=["SimHei"] #设置字体<br>plt.rcParams["axes.unicode_minus"]=False #该语句解决图像中的“-”负号的乱码问题<br>xpoints = np.array([0, 10])<br>ypoints = np.array([0, 60])<br>plt.xlabel("天数") <br>plt.ylabel("收入") <br>plt.plot(x)<br>plt.plot(y)<br><br>plt.show()
<br>
图2:柱状图
x=[1,2,3,4,5,6,7,8,9,10]<br>data=[5,10,23,45,23,42,43,32,43,54]<br>plt.title("")<br>plt.grid(ls="--", alpha=1)<br>plt.bar(x, data ,facecolor="r")
子主题
子主题
对比柱状图
import matplotlib.pyplot as plt<br>import numpy as np<br><br><br>labels = ['G1', 'G2', 'G3', 'G4', 'G5']<br>men_means = [20, 34, 30, 35, 27]<br>women_means = [25, 32, 34, 20, 25]<br><br>x = np.arange(len(labels)) # the label locations<br>width = 0.35 # the width of the bars<br><br>fig, ax = plt.subplots()<br>rects1 = ax.bar(x - width/2, men_means, width, label='Men')<br>rects2 = ax.bar(x + width/2, women_means, width, label='Women')<br><br># Add some text for labels, title and custom x-axis tick labels, etc.<br>ax.set_ylabel('Scores')<br>ax.set_title('Scores by group and gender')<br>ax.set_xticks(x, labels)<br>ax.legend()<br><br>ax.bar_label(rects1, padding=3)<br>ax.bar_label(rects2, padding=3)<br><br>fig.tight_layout()<br><br>plt.show()
子主题
图3:饼图
子主题
import matplotlib.pyplot as plt<br>import numpy as np<br><br>y = np.array([35, 25, 25, 15])<br><br>plt.pie(y)<br>labels=['A','B','C','D'], # 设置饼图标<br>colors=["red", "blue", "yellow", "purple"], # 设置饼图颜色<br>plt.title("各组占比") # 设置标题<br>plt.show()
子主题
0 条评论
下一页