On 07/21/2010 12:27 PM, Benjamin Koep wrote:
Hello,

I got a big problem currently and i really hope that someone here can
help me.

I am working on some graphs that are integrated into a django app. So
far no problem. I had really no experience with matplotlib before but i
managed to create 2 of 3 graph types the way our graphics designer
wants them to be.

The last variation is making me really sick because it has nothing much
to do with an ordinary graph (except the fact that is has bars ;)).

Please take a look at the attachment and give me a hint how i could
realize that. I would really appreciate that.

Kind regards,

Ben


The attached example (adapted mostly from barchart_demo2.py) should guide you in the right direction.

Regards,
João Luís
import numpy as np
import matplotlib.pyplot as plt

data = [ 
        ('Label 1',50),
        ('Label 2',20),
        ('Label 3',12),
        ('Label 4',7),
        ('Label 5',5),
        ('Label 6',2),
        ('Label 7',1.5),
        ('Label 8',1),
        ('Label 9',1),
        ('Label 10',0.5)
       ]

N = len(data)

rankings = []
for e in data:
    rankings.append(e[1])

fig = plt.figure(figsize=(4,9))
ax1 = fig.add_subplot(111,frameon=False,xticks=[],yticks=[])
plt.subplots_adjust(left=0.115, right=0.88)
pos = np.arange(N,0,-1)+0.5    #Center bars on the Y-axis ticks
rects = ax1.barh(pos, rankings, align='center', height=0.2, color='#fe7700')

ax1.axis([0,120,1,11])
ax1.set_title('Top '+str(N))

i = 0
for rect in rects:
    width = int(rect.get_width())

    #Labels
    yloc = rect.get_y()+2.0*rect.get_height()
    ax1.text(0, yloc, str(data[i][0]), horizontalalignment='left',
           verticalalignment='center', color='black')

    #Percent labels
    xloc = width + 3 # Shift the text to the right side of the right edge
    yloc = rect.get_y()+rect.get_height()/2.0 #Center the text vertically in the bar
    ax1.text(xloc, yloc, str(data[i][1])+"%", horizontalalignment='left',
           verticalalignment='center', color='black', weight='bold')
    i+=1

plt.show()

<<attachment: top10.png>>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to