Uncategorized

matplotlib – Python: histogram x-axis in steps


I created a histogram with Python in Power BI and i am looking for a way to create the x-axis in steps.

My current Code:

import matplotlib.pyplot as plt
plt.hist(dataset.deviation_in_percent, bins=80, edgecolor="#6A9662",color="#DDFFDD")
plt.show()

Instead of bins=80 i am looking for following:

For the column deviation_in_percent i would like to start the x-axis at -150% to -100% (create and intervall). Then go on in 2.5% steps like -100% to -97.5%, -97.5% to -95.0% and so on until 100%. Then finish with 100% to 150%. Should be 82 intervalls at the end if i calculated it correctly.

Does someone has an idea how to implement that in the Python code above?

Just to be sure for the y-axis: I suppose that i get the unique number of deviation_in_percent (or in other words the number of rows and not the distinct number of rows) right?

Many Thanks!

I am expecting a histogram like

enter image description here



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *