简体   繁体   English

matplotlib.pyplot问题与子图,np.ones和np.arange?

[英]matplotlib.pyplot issue with subplot, np.ones and np.arange?

I am plotting several data types which share the x axis so I am using the matplotlib.pylot subplots command 我正在绘制共享x轴的几种数据类型,因此我使用matplotlib.pylot subplots命令

The shared x axis is time (in years AD). 共享的x轴是时间(以AD为单位)。 The last subplot I have is the number of independent observations as a function of the time. 我拥有的最后一个子图是独立观测值的数量与时间的关系。 I have the following code 我有以下代码

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

Now when I run this code, the subplot I get only shows the second ax[3] plot and not the first. 现在,当我运行此代码时,得到的子图仅显示第二个ax [3]图,而不显示第一个。 How can I fix this?? 我怎样才能解决这个问题?? Thanks 谢谢

Ok, I think I found an answer. 好吧,我想我找到了答案。 The first plot was plotting but I couldn't see it with the axes so I changed the y limits 第一个图正在绘制,但是我无法用轴看到它,所以我更改了y极限

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

That seemed to work, although is there a way to connect these horizontal lines, perhaps with dashed lines? 尽管有办法将这些水平线(可能是虚线)连接起来,但这似乎可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM