0

I have a data frame with 20 values, and I am trying to bar.plot it using matplotlib. when I do it, I am not seeing the 20 bars but 10. I have 5 nana values in it and 4 of them. Here is a sample of dataframe:

Name             Bonus
Jack Carpenter   890
John Clegg       653
Mike Holiday     367
Rene Moukad      900
...........      ...

my code is standard:

fig,ax = plt.subplots(figsize=(16,6))
plt.bar(df.Name, df.Bonus)
fig.autofmt_xdate(rotation=45)
Herc01
  • 610
  • 1
  • 8
  • 17
  • the code looks okay, pls add the rest of the values and also a screenshot of the graph you are getting. – simpleApp Jun 09 '21 at 01:14
  • Why do you specify `fig.autofmt_xdate(rotation=45)` when the data on the x-axis is not a time series? Does it improve if I remove it? – r-beginners Jun 09 '21 at 01:52
  • Note that your code isn't standard: you are mixing the pyplot interface with the object-oriented interface (see e.g. [matplotlib Axes.plot() vs pyplot.plot()](https://stackoverflow.com/questions/43482191/matplotlib-axes-plot-vs-pyplot-plot)). You could use `ax.bar(df.Name, df.Bonus)` and `ax.tick_params(axis='x', labelrotation=45)`. Are you using a recent matplotlib version? – JohanC Jun 09 '21 at 07:14
  • Your problem doesn't seem reproducible from only the description. Could you provide a full reproducible example with test data? Could you add the output of `df.Bonus.values` and `df.Name.values`? – JohanC Jun 09 '21 at 07:27

0 Answers0