type normed normalized log kind hist example python matplotlib pandas histogram

python - normed - Error Matplotlib/Pandas usando histograma



plot pandas kind (1)

Este error ocurre, entre otras cosas, cuando tiene valores NaN en la serie. ¿Podría ser ese el caso?

Estos NaN no se manejan bien por la función hist de matplotlib. Por ejemplo:

s = pd.Series([1,2,3,2,2,3,5,2,3,2,np.nan]) fig, ax = plt.subplots() ax.hist(s, alpha=0.9, color=''blue'')

produce el mismo error AttributeError: max must be larger than min in range parameter. Una opción es, por ejemplo, eliminar los NaN antes de trazar. Esto funcionará:

ax.hist(s.dropna(), alpha=0.9, color=''blue'')

Otra opción es utilizar el método pandas hist en su serie y proporcionar los axes[0] a la palabra clave ax :

dfj2_MARKET1[''VSPD1_perc''].hist(ax=axes[0], alpha=0.9, color=''blue'')

Tengo un problema al hacer histogramas de objetos de la serie pandas y no puedo entender por qué no funciona. El código funcionó bien antes pero ahora no.

Aquí hay un poco de mi código (específicamente, un objeto de la serie pandas que estoy tratando de hacer un histograma de):

type(dfj2_MARKET1[''VSPD2_perc''])

que genera el resultado: pandas.core.series.Series

Aquí está mi código de trazado:

fig, axes = plt.subplots(1, 7, figsize=(30,4)) axes[0].hist(dfj2_MARKET1[''VSPD1_perc''],alpha=0.9, color=''blue'') axes[0].grid(True) axes[0].set_title(MARKET1 + '' 5-40 km / h'')

Mensaje de error:

AttributeError Traceback (most recent call last) <ipython-input-75-3810c361db30> in <module>() 1 fig, axes = plt.subplots(1, 7, figsize=(30,4)) 2 ----> 3 axes[1].hist(dfj2_MARKET1[''VSPD2_perc''],alpha=0.9, color=''blue'') 4 axes[1].grid(True) 5 axes[1].set_xlabel(''Time spent [%]'') C:/Python27/lib/site-packages/matplotlib/axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs) 8322 # this will automatically overwrite bins, 8323 # so that each histogram uses the same bins -> 8324 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) 8325 m = m.astype(float) # causes problems later if it''s an int 8326 if mlast is None: C:/Python27/lib/site-packages/numpy/lib/function_base.pyc in histogram(a, bins, range, normed, weights, density) 158 if (mn > mx): 159 raise AttributeError( --> 160 ''max must be larger than min in range parameter.'') 161 162 if not iterable(bins): AttributeError: max must be larger than min in range parameter.