matplotlib基础参考

多子图:
一、
plt.subplot2grid(GridSpec, CurSpec, colspan=1, rowspan=1)
#参数分别为:设定网格(2,2), 当前选中网格(0,1), 跨列和跨行

二、
import matplotlib.gridspec as gridspec

# 指定子图行列数
gs = gridspec(3,3)
ax1 = plt.subplot(gs[0,:]) #第一行跨三列
ax2 = plt.subplot(gs[1, :-1]) # 第二行跨1,2列
ax3 = plt.subplot(gs[1:, -1]  # 第三列跨2,3行

三、
fig = plt.figure()
ax1 = fig.add_subplot(331) # 共三行三列第1张图
ax2 = fig.add_subplot(334) # 共3行3列第4张图

四、
plt.gcf() # 获得当前图表的figure对象
plt.gca   # 获得子图的Axes对象
plt.subplot(nRows, nCols, plotNum)
# 行数,列数, 子图对象区域

五、
fig, axises = plt.subplots(nrows=1, ncols=1, sharex=False, sharey=False, gridspec_kw=.., figsize=(4,5))
# figsize单位为inch

fig, axises = plt.subplots(2,2)
axises 会得到二行二列二维列表,可以直接引用绘图
axises.flatten() # 踩平列表
plt.subplots_adjust(hspace=0.5, wspace=0.6)
# 调整子图垂直距离和水平距离

其他参考:

# 坐标轴标签
plt.xlabel('variable x')
plt.ylabel('variable y')
# 坐标轴刻度
plt.xlim(-1, 12)
plt.ylim(-1.5, 1.5)

# 坐标轴刻度间隔
from matplotlib.pyplot import MultipleLocator
ax=plt.gca()
ax.yaxis.set_major_locator(MultipleLocator(2.5))

# 字体与字号
matplotlib.rcParams['font.family'] = ['FangSong']
matplotlib.rcParams['font.size'] = 14
plt.rcParams['axes.unicode_minus']=False
# 图表标题
plt.title('三角函数')
# 图例显示
plt.legend(loc='upper right')
# 网络线
plt.grid()

# 注释图表
plt.annotate('sin(x)', (xs[4], ys[4]), (xs[4]+2, ys[4]), arrowprops=dict

(facecolor='red', edgecolor='red', shrink=0.05), color='r')

#柱状图x轴标签
plt.xticks(ticks=xs ,labels=['a','b'], rotation=60, fontsize=12)

# 饼状图
plt.figure(figsize=(16,8))
# 指定脱离中心块
explode = [0.1, 0,0,0,0,0,0,0,0,0,0]
plt.pie(times, explode=explode,labels=mlabels,autopct='%1.1f%

%',shadow=True,startangle=90, radius=1)
plt.legend(loc='upper right')
# 使图例不与图重叠
plt.axis('equal')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值