![]() |
How can histogram bins be separated and reduce number of labels printed on x-axis? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How can histogram bins be separated and reduce number of labels printed on x-axis? (/thread-38133.html) |
How can histogram bins be separated and reduce number of labels printed on x-axis? - cadena - Sep-07-2022 I have a series of Counter() whose graphs I want to plot. The issue is that there are around 120 to 150 bars that are plotted. I've tried playing with the width but it didn't scale at all for me and all the x-axis labels were mashed together. Therefore, I decided to print instead a graph with only 50 bars but still all the x-axis labels are being printed. I've tried things like labels[:50] but it doesn't work at all and I tried implementing the solution from another post to space out the bars but it was for naught (matplotlib bar chart: space out bars). Therefore, could someone tell me how can I: 1. If I want to print all 120 to 150 bars how can the graph be properly scaled, if possible? 2. How can I print 50 bars x-axis labels instead of all the labels in my data set. 3. How can I space out the bars when dealing with Counter()? The code for my plot function and the screenshots of the graphs are: def plot_count(mycount): labels, values = zip(*mycount.items()) indexes = np.arange(len(labels)) width = 1 plt.bar(indexes[:50], values[:50], width) plt.xticks(indexes + width * 0.5, labels, rotation = 45) plt.show()All bars graph [attachment=1972] 5 bars graph [attachment=1973] RE: How can histogram bins be separated and reduce number of labels printed on x-axis? - Larz60+ - Sep-07-2022 This may help: https://stackoverflow.com/a/56021895 |