Setting axis labels for histogram pandas
This video explains
Setting axis labels for histogram pandas
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Track title: CC I Beethoven Sonata No 31 in A Flat M
--
Chapters
00:00 Question
01:08 Accepted answer (Score 35)
01:34 Thank you
--
Full question
https://stackoverflow.com/questions/4283...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #matplotlib
#avk47
Setting axis labels for histogram pandas
--
Become part of the top 3% of the developers by applying to Toptal
https://topt.al/25cXVn
--
Track title: CC I Beethoven Sonata No 31 in A Flat M
--
Chapters
00:00 Question
01:08 Accepted answer (Score 35)
01:34 Thank you
--
Full question
https://stackoverflow.com/questions/4283...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #matplotlib
#avk47
ACCEPTED ANSWER
Score 38
Labels are properties of axes objects, that needs to be set on each of them. Here's an example that worked for me:
frame = pd.DataFrame([np.random.rand(20), np.sign(np.random.rand(20) - 0.5)]).T
frame.columns = ['Age', 'Survived']
# Note that you can let the hist function do the groupby
# the function hist returns the list of axes created
axarr = frame.hist(column='Age', by = 'Survived', sharex=True, sharey=True, layout = (2, 1))
for ax in axarr.flatten():
ax.set_xlabel("Age")
ax.set_ylabel("Individuals")
ANSWER 2
Score 1
I came here looking for the same thing, but found it easier to do in plotly
import plotly.express as px
px.histogram(df, x="t_depth", nbins=150).update_layout(
xaxis = dict(dtick=10), bargap=0.2
)
ANSWER 3
Score 0
For those looking for a simple one line solution in matplotlib, just tack on .set_xlabel("your_label") to the end.
df.col_to_graph.plot.hist(bins=10, alpha=0.5, figsize=(16, 12)).set_xlabel("col_to_graph label")
