【问题标题】:matplotlib.pyplot issue with subplot, np.ones and np.arange?子图、np.ones 和 np.arange 的 matplotlib.pyplot 问题?
【发布时间】:2014-10-09 14:09:08
【问题描述】:

我正在绘制几种共享 x 轴的数据类型,因此我使用 matplotlib.pylot subplots 命令

共享的 x 轴是时间(以公元年为单位)。我拥有的最后一个子图是独立观察的数量作为时间的函数。我有以下代码

import numpy as np
import matplotlib.pyplot as plt
#
# There's a bunch of data analysis here
#
f, ax = plt.subplots(4, sharex=True)
# Here I plot the first 3 subplots with no issue
x = np.arange(900, 2000, 1)#make x array in steps of 1
ax[3].plot(x[0:28], np.ones(len(x[0:28])),'k')#one observation from 900-927 AD
ax[3].plot(x[29:62], 2*np.ones(len(x[29:62])),'k')#two observations from 928-961 AD

现在,当我运行此代码时,我得到的子图只显示第二个 ax[3] 图,而不是第一个图。我怎样才能解决这个问题??谢谢

【问题讨论】:

    标签: python numpy matplotlib subplot


    【解决方案1】:

    好的,我想我找到了答案。第一个绘图正在绘图,但我无法通过轴看到它,所以我更改了 y 限制

    ax[3].axes.set_ylim([0 7])
    

    这似乎可行,但有没有办法连接这些水平线,也许用虚线?

    【讨论】:

    • 您应该将关于连接线的问题作为一个单独的问题提出,因为它与原始问题没有真正的关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多