Matplotlib

来自Shiyin's note
Shen讨论 | 贡献2017年11月9日 (四) 09:30的版本 →‎plot
跳到导航 跳到搜索
  • 创建不同的图表
plt.figure(1) # 创建图表1
plt.figure(2) # 创建图表2
  • 同一图表上面不同的panel
plt.subplot(211) # 在图表2中创建子图1
plt.subplot(212) # 在图表2中创建子图2
  • 初始化 clear
plt.clf()
  • Tweak spacing to prevent clipping of ylabel
plt.tight_layout()

plot

  • 直方图 num_bins = 50
fig, ax = plt.subplots()
# the histogram of the data
n, bins, patches = ax.hist(x, 50, normed=1)


  • 对数坐标
semilogx #x轴对数
semilogy #y轴对数
set_xscale("log", nonposx='clip')
set_yscale("log", nonposy='clip')
  • 误差棒
errorbar(x, y, xerr=0.1 * x, yerr=5.0 + 0.75 * y)
  • grid
ax.grid()
  • 设置坐标轴的极限
ax.set_ylim(ymin=0.1)

参见[1]