Cumulative Histogram

Hi! I am trying to plot a cumulative histogram in Plotly. This is the code I used for my plot:

fig = go.Figure(data=[go.Histogram(y=df_turbine_name[â€˜0â€™],cumulative_enabled=True)])
fig.show()

The data used is a column from a dataframe.

This is the graph I get:

However, I would like to reverse the shape of the histogram. I plotted what I would like to get in Matplotlib:

(Ignore the red line)

This is the Matplotlib code:

x = df_turbine_name[â€˜0â€™]
plt.figure(figsize=(20,10))
ax = plt.hist(x,100,orientation = â€˜horizontalâ€™ ,cumulative=-1,edgecolor=â€˜blackâ€™)
plt.xlabel(â€˜Frequency [%]â€™)
plt.ylabel(â€˜Power [kW]â€™)
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter(52560))
plt.axhline(y=5000, color=â€˜râ€™, linestyle=â€™-â€™)
plt.show()

Basically, Plotly is doing the cumulative sum the other way round and I was wondering if there is a Plotly equivalent to the â€˜cumulative = -1â€™ from Matplotlib. In case you were wondering if you set â€˜cumulative = Trueâ€™ in Matplotlib you get the same shape of graph I got in Plotly. The -1 value makes the opposite sum of cumulative values.

Any chance someone knows how can I get the histogram I plotted in Matplotlib in Plotly?

Thanks in advance.`Preformatted text`

Hi,

I canâ€™t reproduce your code, but you should be able to reverse the y-axis by adding a line of code in the following way:

``````fig = go.Figure(data=[go.Histogram(y=df_turbine_name['0'],cumulative_enabled=True)])
fig['layout']['yaxis']['autorange'] = "reversed" # reverse the y-axis
fig.show()
``````

Kind regards,
Casper

Hi Casper,

Thanks for the help. However, that is not what I want to do. I do not want to reverse the axes. I want the histogram to give values that are 0 or greater than 0, a thousand o greater than a thousand and so onâ€¦ That way the long purple line would be associated with the 0 value instead of 5000. If I reverse the axis, I get the desired shape but it does not match the numbers. This is because the cumulative sum when cumulative_enabled = True is done the opposite way to how I want to perform it and I was wondering if there is a way to change that.

Thanks

I think what youâ€™re looking for might be:

`plotly.express.ecdf(df.column, ecdfmode='reversed')`