0

I'm trying to make a histogram with two columns and name the labels, but I don't understand how to align the labels with the columns.

Here's what it looks like.

Here is the code (months is the dataset I'm trying to plot):

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

fig, ax = plt.subplots()
fig.set_figheight(6)
fig.set_figwidth(10)
plt.hist(months, bins=2,edgecolor='k', align='left')
ax.set_xticks(np.arange(2),['start of the year','end of the year'])
plt.title('birthdates of the players')
plt.xlabel('birthdate')
plt.ylabel('frequency')
plt.show()
sanyer
  • 11
  • 1
  • 3
    Pls provide the data for `months` array/dataframe in text format. This code wont run without it – Redox Jun 24 '22 at 09:24
  • 1
    The full `months` data isn't needed, just some limited test data that resemble your real data and that reproduce the issue. It is also important to know whether your months are e.g. integers from 1 to 12, or from 0 to 11, or something complete different. You might want to consider a bar plot, e.g. `ax.bar(['start', 'end'] , [(np.array(months)<=6).sum(), (np.array(months)>6).sum()] )`. – JohanC Jun 24 '22 at 09:37
  • Sure, here's an some test data: `data = [4,7,11,1,2,12,12,3,2,2,5,7,2,1,1,5,8,4,3,10,12,2,1,7,4,6,6,9,11,1,13] months = pd.Series(data)`. In this instance, I want to use the 'hist' -function. – sanyer Jun 27 '22 at 07:38

0 Answers0