el histograma acumulativo tiene el último punto en y=0

I am creating histogram with


getting (there are other plots, which are irrelevant now) the violet line


Why is the histogram dropping to zero at the end again? Cumulative functions should be in general non-decreasing. Is there a way to work around this, be it bug or feature?

EDIT: solution (hack):

# histtype=step returns a single patch, open polygon
# just delete the last point

preguntado el 21 de mayo de 12 a las 18:05

2 Respuestas

In case you don't like OP's nice simple solution, here's an over-complicated one where we construct the plot by hand. Maybe it's useful though if you only have access to the histogram counts and can't use matplotlib's hist function.

import numpy as np
import matplotlib.pyplot as plt

data = np.random.randn(5000)
counts, bins = np.histogram(data, bins=20)
cdf = np.cumsum(counts)/np.sum(counts)

    np.vstack((bins, np.roll(bins, -1))).T.flatten()[:-2],
    np.vstack((cdf, cdf)).T.flatten()


Respondido 28 Abr '17, 13:04

This is default behaviour. Think of it as an outline of the histogram as a bar chart. As for a quick workaround, not that I am aware of. A solution would be to calculate the histogram on your own: histograma de python de una sola línea

contestado el 23 de mayo de 17 a las 13:05

Disappointing, but thanks. I can compute the histogram (the one-lines won't do, those are floats which are binned to ragularly-spaced ranges), I actually do it already, though I always prefer tested pre-cooked functions. - eudoxos

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.