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)])

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’]
ax = plt.hist(x,100,orientation = ‘horizontal’ ,cumulative=-1,edgecolor=‘black’)
plt.xlabel(‘Frequency [%]’)
plt.ylabel(‘Power [kW]’)
plt.axhline(y=5000, color=‘r’, linestyle=’-’)

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


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

Kind regards,

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.


I think what you’re looking for might be:, ecdfmode='reversed')