相关疑难解决方法(0)

Matplotlib子图y轴刻度与上图重叠

我试图绘制3个子图,它们之间没有任何空白区域.默认的y轴刻度标签使用显示在y轴右上角的刻度(下例中的1e-8),除了下面的两个绘图与上图重叠之外,这将是正常的.有人知道怎么修这个东西吗?下面是一个小例子.

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'))
Run Code Online (Sandbox Code Playgroud)

情节

所以一个解决方案是使用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'))
Run Code Online (Sandbox Code Playgroud)

但我希望能够将刻度向左移动,以便在可能的情况下在轴外.

python matplotlib

5
推荐指数
1
解决办法
1304
查看次数

标签 统计

matplotlib ×1

python ×1