如何在python中用虚线而不是实线连接子图?我使用此站点https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/subplots_demo.html将3个散点图水平组合,但它们之间有一条实线。有没有办法用虚线将它们连接起来,使其看起来像一个时间轴,就像此图所示
这可以通过在官方参考中自定义示例并隐藏图框的左侧和右侧来完成。此示例仅隐藏框架,因此刻度线仍然存在,并且看起来像虚线。如果对此感到满意,则可以按原样使用它。如果要对其进行自定义,则需要隐藏刻度线并添加带有ax.vlines
或类似的虚线。
import matplotlib.pyplot as plt
import numpy as np
# Some example data to display
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
fig = plt.figure()
gs = fig.add_gridspec(1,3, wspace=0)
axs = gs.subplots(sharex=True, sharey=True)
fig.suptitle('Sharing both axes')
axs[0].plot(x, y ** 2)
axs[1].plot(x, 0.3 * y, 'o')
axs[2].plot(x, y, '+')
axs[0].spines['right'].set_visible(False)
axs[1].spines['left'].set_visible(False)
axs[1].spines['right'].set_visible(False)
axs[1].spines['left'].set_visible(False)
axs[2].spines['left'].set_visible(False)
# Hide x labels and tick labels for all but bottom plot.
for ax in axs:
ax.label_outer()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句