Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

hist plot in percent #320

Closed
ddale opened this Issue Jun 20, 2011 · 9 comments

Comments

Projects
None yet
8 participants
Contributor

ddale commented Jun 20, 2011

Original report at SourceForge, opened Mon Apr 20 04:48:03 2009

except for normed=1 there is no way to control the y output of hist.
being able to specify an output in percent would be useful.

hist(x, percent=1)
plots y/n*100 histograms

Member

pelson commented Aug 19, 2012

Clarification: Implement a "percent" option on hist.
As a workaround, one could just use the normed with a custom formatter:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

plt.hist(np.linspace(0.1, 5.5, 1000), normed=True, bins=range(10))
formatter = mticker.FuncFormatter(lambda v, pos: str(v * 100))
plt.gca().yaxis.set_major_formatter(formatter)

plt.show()

I can't say I am that keen to implement another keyword on the hist function. Thoughts?

Member

WeatherGod commented Aug 20, 2012

Me neither. This is more of a formatter issue than anything else. If anything, we could add an example to the gallery or even the hist api docs.

Member

pelson commented Aug 20, 2012

Good idea. We don't have access to the original author, but lets make the action of this issue to: "Put an example of making a percentage histogram in the mpl gallery".

I'm not sure if its best to use locators for this, or if some clever use of scales might be appropriate.

Owner

mdboom commented Aug 20, 2012

Ok -- and I think if the action is to just create a new example, we can reasonably get this in 1.2, so I'm marking it for that milestone.

Owner

mdboom commented Aug 28, 2012

Closed by #1149.

@mdboom mdboom closed this Aug 28, 2012

Is there any chance of extending the API to accept the percent=1 parameter as @ddale suggested? I saw your example introduced in #1149 and I really don't like the idea of adding so much code just to have yticks as percentages - the normal, textbook way of annotating histograms.

zcesc01 commented Mar 4, 2014

I deffinetly agree with kermit666
it would have been great if it was as simple as adding percent=1 (especially that it is very common for histograms to be plotted in percentage)

Owner

tacaswell commented Mar 4, 2014

It is unlikely that we will add this, the signature for hist is awful enough as it is. We already have a normed kwarg, how would we deal with the case where the user passes in both normed and percent?

A better route might be to add a normed_value kwarg which defaults to 1 such that the result is rescaled so that it integrates to normed_value.

I have never plotted a histogram in percent so I contest the assertions that this is the 'textbook' or even a common thing.

@neggert, comments?

Contributor

neggert commented Mar 4, 2014

This is similar to #1567. I think my thoughts are summed up towards the end of that thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment