Note that there are some explanatory texts on larger screens.

plurals
  1. POMatplotlib - label each bin
    primarykey
    data
    text
    <p>I'm currently using Matplotlib to create a histogram:</p> <p><img src="https://i.stack.imgur.com/B0jJr.png" alt="enter image description here"></p> <pre><code>import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as pyplot ... fig = pyplot.figure() ax = fig.add_subplot(1,1,1,) n, bins, patches = ax.hist(measurements, bins=50, range=(graph_minimum, graph_maximum), histtype='bar') #ax.set_xticklabels([n], rotation='vertical') for patch in patches: patch.set_facecolor('r') pyplot.title('Spam and Ham') pyplot.xlabel('Time (in seconds)') pyplot.ylabel('Bits of Ham') pyplot.savefig(output_filename) </code></pre> <p>I'd like to make the x-axis labels a bit more meaningful.</p> <p>Firstly, the x-axis ticks here seem to be limited to five ticks. No matter what I do, I can't seem to change this - even if I add more xticklabels, it only uses the first five. I'm not sure how Matplotlib calculates this, but I assume it's auto-calculated from the range/data?</p> <p><strong>Is there some way I can increase the resolution of x-tick labels</strong> - even to the point of one for each bar/bin?</p> <p>(Ideally, I'd also like the seconds to be reformatted in micro-seconds/milli-seconds, but that's a question for another day).</p> <p>Secondly, I'd like <strong>each individual bar labeled</strong> - with the actual number in that bin, as well as the percentage of the total of all bins.</p> <p>The final output might look something like this:</p> <p><img src="https://i.stack.imgur.com/UyBGD.png" alt="enter image description here"></p> <p>Is something like that possible with Matplotlib?</p> <p>Cheers, Victor</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload