考虑以下情节:
由此函数产生:
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 来完成吗?需要添加什么代码?
最佳答案
正如 Rutger Kassies 所指出的,实际上有一些“主干”功能可以使我的其他答案中的“手动”方法自动化。水平主干线的函数是 hlines()
(vlines()
用于垂直主干条):
import numpy
from matplotlib import pyplot
x_arr = numpy.random.random(10)-0.5; y_arr = numpy.arange(10)
pyplot.hlines(y_arr, 0, x_arr, color='red') # Stems
pyplot.plot(x_arr, y_arr, 'D') # Stem ends
pyplot.plot([0, 0], [y_arr.min(), y_arr.max()], '--') # Middle bar
documentation hlines()
在 Matplotlib 网站上。
关于python - matplotlib scatterplot(horizontal stem plot)中从x=0到数据点绘制水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14957567/