MATPLOTLIB 定制化画图
直接上代码吧
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from cycler import cycler
t = np.linspace(0.0, 2.0)
alphac = np.sin(t)
alphac_td = np.cos(t)
alpha = np.sin(2.0*t)
plt.rcParams.update({
"legend.fancybox": False,
"legend.frameon": False,
"font.family": "DeJavu Serif",
"font.serif": ["Times"],
"axes.prop_cycle": (cycler('color', ["#4477AA", "#EE6677", "#228833", "#CCBB44"]) + cycler('ls', ['-', '--', ':', '-.'])),
"xtick.direction": 'in',
"xtick.major.size": 3,
"xtick.major.width": 0.5,
"xtick.minor.size": 1.5,
"xtick.minor.width": 0.5,
"xtick.minor.visible": False,
"xtick.top": False,
"ytick.direction": 'in',
"ytick.major.size": 3,
"ytick.major.width": 0.5,
"ytick.minor.size": 1.5,
"ytick.minor.width": 0.5,
"ytick.minor.visible": False,
"ytick.right": False,
"savefig.bbox": 'tight',
"savefig.pad_inches": 0.05,
"figure.figsize": [3.3, 2.5],
"figure.dpi": 600,
"font.size": 6,
"axes.linewidth": 0.5,
'axes.grid': False,
"grid.linewidth": 0.5,
"lines.linewidth": 1.0
})
pparam = dict(xlabel='Time/ (s)', ylabel=r'$\alpha$/rad')
fig, ax = plt.subplots()
ax.plot(t, alphac, label='alphac')
ax.plot(t, alphac_td, label='alphac_td')
ax.plot(t, alpha, label='alpha_real')
leg = ax.legend(fontsize=8)
ax.autoscale(tight=True)
ax.set(**pparam)
fig.savefig('figures/fig3b.jpg', dpi=600)
pparam = dict(xlabel='Time/ (s)', ylabel=r'$\alpha$/rad')
fig, ax = plt.subplots(2, 1)
ax1 = ax[0]
ax1.plot(t, alphac, label='alphac')
ax1.plot(t, alphac_td, label='alphac_td')
ax1.plot(t, alpha, label='alpha_real')
leg = ax1.legend(fontsize=8)
ax1.autoscale(tight=True)
ax1.set(**pparam)
ax2 = ax[1]
ax2.plot(t, alphac, label='alphac')
ax2.plot(t, alphac_td, label='alphac_td')
ax2.plot(t, alpha, label='alpha_real')
leg = ax2.legend(fontsize=8)
ax2.autoscale(tight=True)
ax2.set(**pparam)
fig.savefig('figures/fig33b.jpg', dpi=600)
pparam = dict(xlabel='Time/ (s)', ylabel=r'$\alpha$/rad')
fig, ax = plt.subplots(1, 2)
ax1 = ax[0]
ax1.plot(t, alphac, label='alphac')
ax1.plot(t, alphac_td, label='alphac_td')
ax1.plot(t, alpha, label='alpha_real')
leg = ax1.legend(fontsize=8)
ax1.autoscale(tight=True)
ax1.set(**pparam)
ax2 = ax[1]
ax2.plot(t, alphac, label='alphac')
ax2.plot(t, alphac_td, label='alphac_td')
ax2.plot(t, alpha, label='alpha_real')
leg = ax2.legend(fontsize=6)
ax2.autoscale(tight=True)
ax2.set(**pparam)
fig.savefig('figures/fig333b.jpg', dpi=600)
这里边最大的问题就是Times 这个字体经常没法用,可能需要单独拷贝进matplotlib的字体文件夹里 画出图来长这样
- 竖着排
- 横着排
- 就一个
|