我正在尝试在 Python Matplotlib 中制作伪彩色图像图,但我的布局有一个小问题 - 轴刻度标签是非常小的数字(1e-7 左右),所以 Matplotlib 将指数放在整个轴。这很好,但它与 x 轴标签和标题重叠!
除了向上破解标题和向下破解 xlabel 之外,有没有更好的方法来解决这个问题(如果这是要走的路,那么最好的方法是什么?)我正在尝试绘制很多不同的东西最大程度的代码重用,所以如果 Matplotlib 有办法在不手动更改文本定位的情况下解决这个问题,那将是最好的!
这是我生成此图的方式:
fig = Figure(figsize=(5.5, 4.25))
ax = fig.add_subplot(111)
ax.set_title('The title', size=12)
ax.set_xlabel('The xlabel', size=10)
ax.set_ylabel('The Ylabel', size=10)
ax.ticklabel_format(scilimits=(-3,3))
pcm = ax.pcolor(X, Y, Z, cmap=cm.jet) #X,Y is a meshgrid and Z is the function evaluated on it
ax.get_figure().colorbar(pcm, ax=ax, use_gridspec=True)
ax.set_axes([0, 1e-3, -5e-7, 5e-7])
#Some code for the hatching at the top and bottom of the plot
for ticklabel in ax.get_xticklabels():
ticklabel.set_size(8)
for ticklabel in ax.get_yticklabels():
ticklabel.set_size(8)
ax.get_xaxis().get_offset_text().set_size(8)
ax.get_yaxis().get_offset_text().set_size(8)
fig.subplots_adjust()
c = FigureCanvas(fig)
c.print_figure('filename.png', dpi=300)