Matplotlib:将图形向右移动
我在一张图像中有两张图表,每张图表有 5 个点。它们在 X 轴上的值并不重要,我所需要的只是它们在 X 轴上均匀分布。
import matplotlib.pyplot as plt
data = [43,51,44,73,60]
data2 = [34,25,42,53,61]
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot(data, '-o', color='#000000', lw=1, ms=6)
ax.plot(data2, '-o', color='#000000', lw=1, ms=6)
plt.show()
这将创建一个如下图所示的图表。
我需要第二张图(使用 data2 点的图)从 X 轴上的 5 开始,而不是从 0 开始,这意味着它将点位于 (5,34)、(6,25)、(7,42)、(8,53)、(9,61)。我该怎么做?
I have two graphs with in one image, each with 5 points. Their value on the X axis is not important, all that I require is that they're all equally distributed on it.
import matplotlib.pyplot as plt
data = [43,51,44,73,60]
data2 = [34,25,42,53,61]
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.plot(data, '-o', color='#000000', lw=1, ms=6)
ax.plot(data2, '-o', color='#000000', lw=1, ms=6)
plt.show()
This creates a graph like the one below.
I need the second graph (the one using the data2 points) to start from 5 on the X axis, not from 0, meaning it'll have the points at (5,34),(6,25),(7,42),(8,53),(9,61). How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
列出 X 值,
并使用
注意,您还可以使用
range (5,10)
或 numpy 的arange(5,10)
或linspace(5,9,5)
生成 X 值。Make a list of the X values,
and use
Note that you could also use
range(5,10)
or numpy'sarange(5,10)
orlinspace(5,9,5)
to generate the X values.