I'm trying to plot the following dataset, but, for some reason I can't get de ticks right. It seems they are always offplace.
y = [0.72727273,0.5,0.33333333,0.4375,0.4375,0.14285714,0.36363636,1.44444444,0.53333333,0.26666667,0.625,0.71428571,0.4,1.21428571,0.22222222,0.09090909,0.35714286,0.07142857,0.4,1.46666667,0,1.44444444,0.42857143,0.13333333,0.5,0.25,0,0.44444444,0.33333333,0.46153846,0,0.57142857,0.8,0.35714286,0.16666667,0.45454545,0,0.95,0,0,0,0.15384615,0.5,1,3.11111111,3,2.7,0.8,1.66666667,0.69230769,0,1.66666667,1,3,6.5,3.75,0,6,0,0]
month_year = ['Jun 2014', 'Jul 2014', 'Aug 2014', 'Sep 2014', 'Oct 2014', 'Nov 2014', 'Dec 2014', 'Jan 2015', 'Feb 2015', 'Mar 2015', 'Apr 2015', 'May 2015', 'Jun 2015', 'Jul 2015', 'Aug 2015', 'Sep 2015', 'Oct 2015', 'Nov 2015', 'Dec 2015', 'Jan 2016', 'Feb 2016', 'Mar 2016', 'Apr 2016', 'May 2016', 'Jun 2016', 'Jul 2016', 'Aug 2016', 'Sep 2016', 'Oct 2016', 'Nov 2016', 'Dec 2016', 'Jan 2017', 'Mar 2017', 'Apr 2017', 'May 2017', 'Jun 2017', 'Jul 2017', 'Aug 2017', 'Sep 2017', 'Aug 2018', 'Sep 2018', 'Oct 2018', 'Nov 2018', 'Dec 2018', 'Feb 2019', 'Mar 2019', 'Apr 2019', 'May 2019', 'Jun 2019', 'Jul 2019', 'Aug 2019', 'Sep 2019', 'Oct 2019', 'Dec 2019', 'Jan 2020', 'Feb 2020', 'Mar 2020', 'Sep 2020', 'Oct 2020', 'Nov 2020']
I'm using the following piece of code to do the plot.
fig, ax = plt.subplots(figsize = (10,4)) ax.bar(month_and_year_name,y, width =1 , align = 'center', linewidth = 0.5, edgecolor = 'yellow' ) ax.tick_params(axis='x', rotation=45) # plt.tight_layout() plt.savefig("files/sparks_in_all_logs.png", dpi = 300)
As you can see, not only the ticks are completely missplace they are also out of the png i've saved.
What I'm doing wrong here? what should I do to correct this plot? And, for the future I'll add more and more information in both parameters, y and month_year. Is there a way to properly set the figure size with that in mind? (each month will have a new pair of y and month_year)
https://stackoverflow.com/questions/66811331/what-would-be-the-best-way-to-plot-a-dataset-with-months-as-x-ticks March 26, 2021 at 01:06PM
没有评论:
发表评论