python matplotlib legend shows first entry of a list only
Question: I could not get all the legends to appear in matplotlib.

My Labels array is:

    
    
    lab = ['Google', 'MSFT', 'APPL', 'EXXON', 'WMRT']
    

I use the below code to add the legend:

    
    
    ax.legend(lab,loc="best")
    

Am seeing only 'Google' in top right corner. How to show all labels? ![enter
image description here](http://i.stack.imgur.com/uqVhf.png)

Full code:

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    from itertools import cycle, islice
    
    menMeans = (8092, 812, 2221, 1000, 562)
    N = len(menMeans)
    
    lab = ['Google', 'MSFT', 'APPL', 'EXXON', 'WMRT']
    
    ind = np.arange(N)  # the x locations for the groups
    width = 0.35       # the width of the bars
    
    fig, ax = plt.subplots()
    my_colors = list(islice(cycle(['b', 'r', 'g', 'y', 'k']), None, N))
    rects1 = ax.bar(ind, menMeans, width, color=my_colors,label=lab)
    
    # add some
    ax.set_ylabel('Count')
    ax.set_title('Trending words and their counts')
    ax.set_xticks(ind+width)
    ax.legend(lab,loc="best")
    plt.show()
    


Answer: Your problem is that you're only plotting once with a single `ax.bar` and as
such your legend can only have one item (for that one plot). One way to get
around this, for your plotting script, is to change the xticks and xticklabels
as shown below.

When you create a legend you create an entry for each `matplotlib.artist`
object that you have created through plotting. These objects could be a set of
data points, or a line, or a set of bars in a bar chart. It doesn't matter if
you have 5 or 10 bars in your bar chart as **you've still only plotted one bar
chart**. This means you will end up only having one entry in your legend.

I have used `ax.set_xticks(ind+width/2)` to place the tick positions directly
underneath your bars, I have then set these labels using your `lab` list with
`ax.set_xticklabels(lab)`.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    from itertools import cycle, islice
    import matplotlib.ticker as mtick
    
    menMeans = (8092, 812, 2221, 1000, 562)
    N = len(menMeans)
    
    lab = ['Google', 'MSFT', 'APPL', 'EXXON', 'WMRT']
    
    ind = np.arange(N)  # the x locations for the groups
    width = 0.35       # the width of the bars
    
    fig, ax = plt.subplots()
    
    my_colors = list(islice(cycle(['b', 'r', 'g', 'y', 'k']), None, N))
    
    rects1 = ax.bar(ind, menMeans, width, color=my_colors,label=lab)
    
    ax.set_ylabel('Count')
    ax.set_title('Trending words and their counts')
    
    plt.xticks(rotation=90)
    
    ax.set_xticks(ind+width/2)
    ax.set_xticklabels(lab)
    
    plt.show()
    

![Plot](http://i.stack.imgur.com/qWXFA.png)

