1.matplotlib package
pip install matplotlib或者直接选用anaconda作为解释器
2.直线
import matplotlib.pyplot as plt
x = [0, 1]
y = [0, 1]
plt.figure()
plt.plot(x, y)
plt.show()
2.饼图pie
import matplotlib.pyplot as plt
labels='frogs','hogs','dogs','logs'
sizes=15,20,45,10
colors='yellowgreen','gold','lightskyblue','lightcoral'
explode=0,0.1,0,0
plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=50)
plt.axis('equal')
plt.show()
3.叠加与子图
在plot中写入多个横纵轴关系。
plt.plot(t, t,'--', t, t**2, 'bs', t, t**3)
4.标注及特殊符号
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0.0,10.0)
y1 = 0.75*x1
x2 = np.linspace(10.0,15.0)
y2 = 7.5*3-1.5*x2
x3 = np.linspace(0.0,10.0)
y3 = np.linspace(7.5,7.5)
x4 = np.linspace(10.0,10.0)
y4 = np.linspace(0,7.5)
plt.figure(figsize=(8,4)) #创建绘图对象
plt.plot(x1,y1,"k",linewidth=1) #在当前绘图对象绘图(X轴,Y轴,线宽度)
plt.plot(x3,y3,"k--",linewidth=1)
plt.plot(x4,y4,"k--",linewidth=1)
plt.plot(x2,y2,"k",linewidth=1) #在当前绘图对象绘图(X轴,Y轴,线宽度)
plt.ylim(0,12)
plt.xlim(0,25)
plt.xticks([10,15],('T',r'$\mathrm{T+t}_p$'))#隐藏刻度
plt.yticks([])#隐藏刻度
#ax = plt.gca()
#ax.spines['right'].set_color('none')#去掉上边框
#ax.spines['top'].set_color('none')#去掉右边框
plt.text(-1.2, 7.7,r'$\mathrm{J}_i^{T}$',fontsize=15,style = "italic", horizontalalignment='center',verticalalignment='center')
plt.text(25, -1,r'$\mathrm{Time}$',fontsize=15, style = "italic", horizontalalignment='center',verticalalignment='center')
plt.text(-1.5, 12,r'$\mathrm{J}_i\ \mathrm{level}$',fontsize=15,style = "italic", horizontalalignment='center',verticalalignment='center')
plt.text(5, 4.5,r'$\mathrm{a}_i$',fontsize=15, style = "italic", horizontalalignment='center',verticalalignment='center')#ai
plt.text(12.5, 4.5,r'$\mathrm{c}_i$',fontsize=15, style = "italic", horizontalalignment='center',verticalalignment='center')#ci
plt.text(5, 1,r'$\mathrm{J}_i^{T}\mathrm{/a}_i$',fontsize=15, style = "italic", horizontalalignment='center',verticalalignment='center')#
plt.text(12.5, 1,r'$\mathrm{J}_i^{T}\mathrm{/c}_i$',fontsize=15, style = "italic", horizontalalignment='center',verticalalignment='center')#
plt.show()
这图是论文中的,自己通过python画的,标注很随意,字体也没能去调整。
5.堆叠柱状图
import matplotlib.pyplot as plt
import numpy as np
N = 4
chp_power = (7, 10, 10, 10)
grid = (0, 2, 6, 5)
ind = np.arange(N)
width = 0.35
x = [0, 1, 2, 3]
y = [7, 12, 16, 15]
p2 = plt.bar(ind, chp_power, width,color='#34B4C2', bottom=grid)
p1 = plt.bar(ind, grid, width, color='#613B8C')
p3 = plt.plot(x, y, color='black', marker="^", linestyle='--', linewidth=1)
plt.ylabel('Power Generated')
plt.xlabel('Time Interval')
plt.title('Power Scheduling Plan')
plt.xticks(ind, ('1', '2', '3', '4'))
plt.yticks(np.arange(0, 30, 10))
plt.legend((p1[0], p2[0],p3[0]), ('Grid','Gas Turbine', 'Power Demand'))
plt.show()