【发布时间】:2013-02-04 03:20:00
【问题描述】:
考虑以下情节:
由这个函数产生:
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 的正负差异。更清楚地可视化这一点会很好,例如
- 强调 x=0 轴
- 从 x=0 到绘图标记画一条线
这可以用 matplotlib 完成吗?需要添加什么代码?
【问题讨论】:
-
要从 x=0 到点绘制一条“线”,您应该简单地尝试制作一个条形图,而不是或叠加在现有的条形图上。
-
您有一个对数图,即无法显示点 x=0。
-
您可以使用 ax.vlines() 或 ax.axvline(),但实际上它们不会在日志中的 x=0 处显示。
-
@DavidZwicker 感谢您指出这一点。我需要修改我的绘图以便显示 0。
-
@RutgerKassies:好点。还有更直接的
pyplot.vlines()和pyplot.hlines(),应用于当前坐标区。
标签: python matplotlib plot ipython-notebook