- import matplotlib.pyplot as plt
from pylab import *
#text 函数可以做文本注释,且支持 LaTeX 格式:
fig, ax = plt.subplots()
xx=linspace(0,5,5)
ax.plot(xx, xx**2, xx, xx**3)
ax.text(0.15, 0.2, r"$y=x^2$", fontsize=20, color="blue")
ax.text(0.9, 0.1, r"$y=x^3$", fontsize=20, color="green");
plt.savefig('E:\python\慕课网 python\.idea\photo\文本注释.png',dpi=400,bbox_inches='tight')
# fig
# 带有多子图与插图的图
#
# fig.add_axes 在图中加入新坐标轴
#
# subplots, subplot2grid,gridspec等 子图布局管理器
#
# subplots
fig, ax = plt.subplots(2, 3)
fig.tight_layout()
plt.savefig('E:\python\慕课网 python\.idea\photo\规则排列子图.png',dpi=400,bbox_inches='tight')
plt.show()
fig = plt.figure()
ax1 = plt.subplot2grid((3,3), (0,0), colspan=3)
ax2 = plt.subplot2grid((3,3), (1,0), colspan=2)
ax3 = plt.subplot2grid((3,3), (1,2), rowspan=2)
ax4 = plt.subplot2grid((3,3), (2,0))
ax5 = plt.subplot2grid((3,3), (2,1))
fig.tight_layout()
plt.savefig('E:\python\慕课网 python\.idea\photo\不规则排列子图.png',dpi=400,bbox_inches='tight')
plt.show()
|
|