如下图所示 在子图(2,1,1)中,线型为“-”,但看起来像一条直线。 在子图(2,1,2)中,线型是“:”,看起来更好,但也有同样的问题。 我怎样才能得到一条简洁的虚线?
plt.subplot(2, 1, 1)
plt.plot(df['START_DATETIME'],df['RESULT_DESC'],'o')
plt.plot(df['START_DATETIME'],(xbar,) * num)
plt.plot(df['START_DATETIME'],((UCL,) * num),'--')
plt.plot(df['START_DATETIME'],((LCL,) * num),'--')
plt.subplot(2, 1, 2)
plt.plot(df['START_DATETIME'],df['range'],'o')
plt.plot(df['START_DATETIME'],(rbar,) * num)
plt.plot(df['START_DATETIME'],((UCLR,) * num),':')
plt.axhline(y=UCLR, xmin=starttime, xmax=stoptime)
plt.plot(df['START_DATETIME'],((0,)*num),':')
我认为问题是你有太多未排序的点。你的代码在绘制很多直线,它们各自都是虚线/虚线,但一条在另一条上看起来更像一条直线(我不知道为什么不是一条直线,但我猜是因为matplotlib内部并不总是从起始点开始,以节省一些时间-否则绘制像这种情况下成千上万的线将永远)。你知道吗
因为你只是画一条直线,所以解决方法是把输入限制在两点,第一点和最后一点。没有你的数据,我用随机数据复制了它,见下:
从matplotlib
输出:
相关问题 更多 >
编程相关推荐