Thank you for the links, but I had trouble to get them running with Matplotlib 1.0.1. However, I downloaded the source code from the Matplotlib book ( http://www.packtpub.com/support?nid=4110 ) and in chapter 9 is an example (7900_09_04_cvs.py) with work with csv files.

I have tried to modify the original code, because my data is stored in dict. Please find below my problem code:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib.font_manager as font_manager
    

    types = sorted(cul_stat.keys()) #year
    print "types = ", types
    data_info = {}
    
    for type in types:
        for d in cul_stat[type]['Total'].data_info.keys():
            if d not in data_info:
                data_info[d] = 0
                
    data_info_all = sorted(data_info.keys())
    print "data_info_all = ", data_info_all #countries

    data = []
    for type in types:
        data_amount = []
        for d in data_info_all:
            try:
                data_amount.append(cul_stat[type]['Total'].data_info[d])
            except KeyError:
                data_amount.append(0)
                
        data.append(data_amount)
    print 'data = ',data
           
    # prepare the bottom array
    bottom = np.zeros(len(types))
    print "bottom = ", bottom 
    width = .8
    # for each line in data
    for i in range(len(data)):
        # create the bars for each element, on top of the previous bars
        print "????", data[i], len(data[i])
        bt = plt.bar(range(len(data[i])), data[i], width=width,
                     color=cm.hsv(32*(i)), label=data_info_all[i],
                     bottom=bottom)
        # update the bottom array
        bottom += data[i]

    # label the X ticks with years
    plt.xticks(np.arange(len(types))+width/2, types)
    
    # some information on the plot
    plt.xlabel('Years')
    plt.ylabel('Population (in billions)')
    plt.title('World Population: 1950 - 2050 (predictions)')

    # draw a legend, with a smaller font
    plt.legend(loc='upper left',
               prop=font_manager.FontProperties(size=7))

    plt.subplots_adjust(bottom=0.11, left=0.15)
    plt.savefig('7900_09_04.png')


Output:
+++++++

types =  ['d1', 'd2', 'd3', 'd4', 'd5']
data_info_all =  ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9', 'x10']
data =  [[484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420], [3236, 6, 4, 8099, 8, 3833, 2285, 3, 8054, 3170], [1396, 6, 2, 3588, 5, 1450, 1111, 3, 3478, 1380], [492, 2, 1, 1257, 3, 528, 298, 2, 1240, 506], [21, 0, 0, 44, 1, 20, 11, 0, 50, 17]]

bottom =  [ 0.  0.  0.  0.  0.]
???? [484, 1, 2, 1119, 3, 570, 314, 0, 1185, 420] 10
Traceback (most recent call last):
  File "snp_density.py", line 196, in <module>
    total_chr_overview(len_ref_seqs, cul_stat, args.chr)
  File "snp_density.py", line 143, in total_chr_overview
    bottom=bottom)
  File "/home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1908, in bar
    ret = ax.bar(left, height, width, bottom, **kwargs)
  File "/home/uqmlore1/apps/pymodules/lib/python2.7/site-packages/matplotlib/axes.py", line 4616, in bar
    nbars)
AssertionError: incompatible sizes: argument 'bottom' must be length 10 or scalar
+++++

What did I wrong?

Thank you in advance.



On Wed, Sep 28, 2011 at 5:13 PM, Klonuo Umom <klonuo@gmail.com> wrote:
IMHO, when looking for basics and even more with intent to replicate some graph, it's easy to start by looking at matplotlib gallery: http://matplotlib.sourceforge.net/gallery.html and find best match.

In you case:
http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html
http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html

for stacked bars, then look at code magic.

I'm new user to matplotlib also, and was looking for easy way to create stacked bars some time ago, but unfortunately it's a bit more complicated than regular plot 'stuff'. I found gnuplot easier for stacked bars, but than as said my experience with matplotlib is basic


Cheers


On Wed, Sep 28, 2011 at 8:54 AM, Michal <mictadlo@gmail.com> wrote:
Hello,

How is it possible to do this with Matplotlib?

Thank you in advance.



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users