我想绘制3个子图,而它们之间没有任何空白。默认的y轴标签标签使用显示在y轴右上角的标度(下面例子中的1e-8),除了与上面的图相重叠的较低的两个标绘图外,这将是很好的。有人知道怎么修这个东西吗?下面是一个小例子。Matplotlib子图y轴缩放比例与上面的图形重叠
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.ticker import MaxNLocator
x = np.arange(0,200)
y = np.random.rand(200) * 10e-8
fig = plt.figure(figsize=(10,15))
gs1 = gridspec.GridSpec(3, 3)
gs1.update(left=0.1, right=0.9, bottom=0.5, hspace=0.0)
ax0a = plt.subplot(gs1[0, :])
ax0b = plt.subplot(gs1[1, :])
ax0c = plt.subplot(gs1[2, :])
ax0a.set_xticklabels([])
ax0b.set_xticklabels([])
ax0a.plot(x,y)
nbins = len(ax0a.get_xticklabels())
ax0a.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))
ax0b.plot(x,y)
ax0b.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))
ax0c.plot(x,y)
ax0c.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))
这样一个解决方案是使用mtick,
import matplotlib.ticker as mtick
ax0a.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.1e'))
ax0b.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.1e'))
ax0c.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.1e'))
,但我宁愿能规模转移到左边,这样它的轴线之外,如果可能的。
你能否划分你的数据通过'10e8',只需将xtick标签重命名为'r'$ 10^x $''? – GWW