考虑以下情节:
由此函数生成:
def timeDiffPlot(dataA, dataB, saveto=None, leg=None):
labels = list(dataA["graph"])
figure(figsize=screenMedium)
ax = gca()
ax.grid(True)
xi = range(len(labels))
rtsA = dataA["running"] / 1000.0 # running time in seconds
rtsB = dataB["running"] / 1000.0 # running time in seconds
rtsDiff = rtsB - rtsA
ax.scatter(rtsDiff, xi, color='r', marker='^')
ax.scatter
ax.set_yticks(range(len(labels)))
ax.set_yticklabels(labels)
ax.set_xscale('log')
plt.xlim(timeLimits)
if leg:
legend(leg)
plt.draw()
if saveto:
plt.savefig(saveto, transparent=True, bbox_inches="tight")
这里重要的是x = 0
值的正负差异。最好能更清楚地看到这一点,例如
这可以用matplotlib完成吗?需要添加什么代码?
正如Rutger-Kassies所指出的,实际上有一些“stem”函数可以从我的另一个答案中自动实现“手动”方法。水平阀杆的功能是
hlines()
(vlines()
用于垂直阀杆):Matplotlib网站上有
hlines()
的documentation。(请参阅我的另一个答案,以获得更快的解决方案。)
Matplotlib提供垂直的“stem”条:http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.stem。但是,我找不到
stem()
的水平等价物。尽管如此,通过多次调用(每个调用一个),仍然可以很容易地绘制水平杆。下面是一个例子
结果如下:
但是,请注意,当x在对数刻度上时,从x=0绘制条线是没有意义的,正如David Zwicker指出的,因为x=0在x轴的左侧是无限远的。
相关问题 更多 >
编程相关推荐