Matplotlib不绘制负值:极具误导性

时间:2019-07-07 07:33:54

标签: python pandas numpy matplotlib

Matplotlib不会绘制我的系列的负值,因此其绘制极具误导性。

这是系列和情节:

df[df.SKU=='ProductB'].Sales.values

输出

array([ nan,  nan,  nan, -23.,
> 446., 361., 229., 219., 495., 278., 316.,
>        -50., 442., 459., 392., 381., 288., 240., 361., -45., 241., 328.,
>        233., 293., 387., 385., 442., -23., 376., 483., 301., 489., 487.,
>        464., 488.])

图:plt.plot(df[df.SKU=='ProductB'].Sales.values) enter image description here

这是怎么回事?

1 个答案:

答案 0 :(得分:0)

您的代码确实绘制了系列的负值。

# it's the same one you provided with additional '-2000.' value at the end
a = np.array([ np.nan,  np.nan,  np.nan, -23., 446., 361., 229., 219., 495., 278., 316., 
           -50., 442., 459., 392., 381., 288., 240., 361., -45., 241., 328.,
           233., 293., 387., 385., 442., -23., 376., 483., 301., 489., 487.,
           464., 488., -2000.])

尝试使用相同的代码绘制此数组:

table](www.asd)[![enter image description here] 1


因此,正如您所看到的,问题在于您的负值非常接近零,以至于考虑到情节的ylim,您实际上看不到它们。