制作熊猫系列的直方图

我想制作熊猫系列的直方图(prior_fails),但我不断收到以下 ValueError:


ValueError: view limit minimum -36814.8560105 is less than 1 and is an 

invalid Matplotlib date value. This often happens if you pass a non-datetime 

value to an axis that has datetime units

这就是我调用直方图的方式


plt.hist(prior_fails)

plt.ylabel('Frequency')

plt.xlabel('Days of Failure (%)')

先前失败是具有以下索引的系列:


prior_fails.index

Out[85]: 

Index([u'prior110', u'prior113', u'prior118', u'prior141', u'prior144',

   u'prior16', u'prior217', u'prior223', u'prior245', u'prior29',

   u'prior352', u'prior360', u'prior370', u'prior438', u'prior55',

   u'prior59', u'prior60', u'prior68', u'prior74', u'prior88'],

  dtype='object')

和内容:


prior_fails

Out[86]: 

prior110    13.962170

prior113    10.861125

prior118    21.304131

prior141    11.309109

prior144    11.363863

prior16     14.479841

prior217    10.403186

prior223    14.201095

prior245     7.974116

prior29     17.401692

prior352     9.860627

prior360    12.339472

prior370    16.207068

prior438    16.381284

prior55     20.587357

prior59     10.452962

prior60     15.828771

prior68     16.769537

prior74     16.918865

prior88      9.805874

dtype: float64

任何帮助将不胜感激。我对python相当陌生。谢谢!


慕姐4208626
浏览 145回答 2
2回答

慕村9548890

好吧,在使用 matplotlib 或 pandas(使用 matplotlib 本身进行绘图)绘制直方图时,我没有收到任何错误。import pandas as pddata = {'ind': ['prior110', 'prior113', 'prior118', 'prior141', 'prior144', 'prior16', 'prior217', 'prior223', 'prior245', 'prior29', 'prior352', 'prior360', 'prior370', 'prior438', 'prior55', 'prior59', 'prior60', 'prior68', 'prior74', 'prior88'],        'val': [13.96217, 10.861125, 21.304131, 11.309109, 11.363863, 14.479841, 10.403186, 14.201095, 7.974116, 17.401692, 9.860627, 12.339472, 16.207068, 16.381284, 20.587357, 10.452962, 15.828771, 16.769537, 16.918865, 9.805874]}prior_fails = pd.DataFrame(data, columns=['ind', 'val'])prior_fails.set_index('ind', inplace=True)prior_fails# with pandasprior_fails.hist()plt.ylabel('Frequency')plt.xlabel('Days of Failure (%)')plt.title('Histogram')# with matplotlibimport matplotlib.pyplot as pltplt.hist(prior_fails.val)plt.ylabel('Frequency')plt.xlabel('Days of Failure (%)')如果您仍然遇到错误,也许您可以%matplotlib inline在绘图之前尝试。这将改变 matplotlib 使用的后端inline。有时,无论出于何种原因,默认后端可能会损坏或损坏,因此您可以尝试更改后端以查看是否是导致问题的原因。还有其他后端,如qt5、agg等。因此,如果这也不能解决您的问题,也许您可以尝试其中的一些后端。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python