How to manage different labels in a bar chart, taking data from a text file?
<p>I'm new in using matplotlib, so I'm having some problems. I must create a bar chart with different labels, for each website that I have.
The file is like the following:</p>

<pre><code>1001 adblock 12
1001 badger 11
1001 disconnect 15
1001 ghostery 15
1001 nottrack 14
1001 origin 15
1001 policy 16
1001 ultimate 14
4ruote adblock 12
4ruote badger 1
4ruote disconnect 14
4ruote ghostery 27
4ruote nottrack 9
4ruote origin 26
4ruote policy 34
4ruote ultimate 20
...... ........ ...
</code></pre>

<p>My goal is to create a bar chart in which I have:</p>

<ol>
<li><p>on the x axis sites (first column of the file), is a string</p></li>
<li><p>on the y axis the values (third column of the file) for that site (that are 8 times repeated inside the file), so 8 integer values</p></li>
<li><p>labels that, for a specific site, are present in the second column (strings).</p></li>
</ol>

<p>I read different answers but each one didn't threat this comparison between labels, for a same variable.
What I'm doing is read the file, splitting the row and taking the first and third column, but how can I manage the labels?</p>

<p>Let's assume that you have read the websites into 8 different datasets (adblock, badger, disconnect, etc). You can then use the logic below to plot each series and show their labels on a legend. </p>

<pre><code>import numpy
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
#this is your number of datasets
x = numpy.arange(8)
width = 0.1
#plot each dataset here, offset by the width of the preceding bars
b1 = ax.bar(x, adblock, width, color='r')
b2 = ax.bar(x + width, badger, color='g')
b3 = ax.bar(x + width*2, disconnect, color='m')
legend([b1[0], b2[0], b3[0]], ['adblock', 'badger',
                                          'disconnect'])
plt.show()
</code></pre>

python matplotlib