Hello,
I really like Python and Matplotlib, and recommend it to all my colleagues.
I have found this plot:
http://en.wikipedia.org/wiki/File:Operating_system_usage_share.svg
I think it looks good, it is made in R. The code looks clean, not many
settings etc.
I wanted to see if I could make a similar plot in Matplotlib.
So far, this is what I got:
from pylab import *
data = [37.92, 29.72, 13.09, 7.40, 2.80, 2.07]
x = arange(len(data))
ax = subplot(111)
bar(x, data)
xticks( x + 0.5, ("Windows\nXP", "Windows\n7", "Windows\nVista",
"MacOS X", "iOS", "Linux") )
title("Usage share of web client operating systems: May 2011")
ylabel("Percent Usage")
savefig('barplot.png',format='png')
I have stolen most of the code from an example:
http://matplotlib.sourceforge.net/examples/pylab_examples/custom_ticker1.html
I havent figured out how to color the bars differently, does anybody
know how to do this?
Sincerely
Michael
Hello Michael,
I will do this by defining a an array of colors and then plot each bar separately using a for loop
U can assign a color to the bar with the facecolor keyword.
U can use your code with a slight modifications
from pylab import *
data = [37.92, 29.72, 13.09, 7.40, 2.80, 2.07]
x = arange(len(data))
ax = subplot(111)
fcarray = ['red','blue','green','black','cyan','magenta'] # this is the array of colors u give
for i in range(len(x)):
bar(x[i],data[i],fc=fcarray[i])
xticks( x + 0.5, ("Windows\nXP", "Windows\n7", "Windows\nVista"
"MacOS X", "iOS", "Linux") )
title("Usage share of web client operating systems: May 2011"
ylabel("Percent Usage")
savefig('barplot.png',format='png')
Regards
Bhargav
···
On Aug 3, 2011, at 2:45 PM, Michael Klitgaard wrote:
Hello,
I really like Python and Matplotlib, and recommend it to all my colleagues.
I have found this plot:
File:Operating system usage share.svg - Wikipedia
I think it looks good, it is made in R. The code looks clean, not many
settings etc.
I wanted to see if I could make a similar plot in Matplotlib.
So far, this is what I got:
from pylab import *
data = [37.92, 29.72, 13.09, 7.40, 2.80, 2.07]
x = arange(len(data))
ax = subplot(111)
bar(x, data)
xticks( x + 0.5, ("Windows\nXP", "Windows\n7", "Windows\nVista",
"MacOS X", "iOS", "Linux") )
title("Usage share of web client operating systems: May 2011")
ylabel("Percent Usage")
savefig('barplot.png',format='png')
I have stolen most of the code from an example:
http://matplotlib.sourceforge.net/examples/pylab_examples/custom_ticker1.html
I havent figured out how to color the bars differently, does anybody
know how to do this?
Sincerely
Michael
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
bar returns a list of patches
lPatches = bar(x, data)
N = len(lPatches)
lColors = cm.jet(range(N)*256./N)
# or lColors = ['r', 'b', 'y', ... ]
for ind,el in enumerate(lPatches):
el.set_color(lColors)
# or set_edgecolor or set_facecolor
···
Le mercredi 03 août 2011 à 14:45 +0200, Michael Klitgaard a écrit :
Hello,
I really like Python and Matplotlib, and recommend it to all my colleagues.
I have found this plot:
File:Operating system usage share.svg - Wikipedia
I think it looks good, it is made in R. The code looks clean, not many
settings etc.
I wanted to see if I could make a similar plot in Matplotlib.
So far, this is what I got:
from pylab import *
data = [37.92, 29.72, 13.09, 7.40, 2.80, 2.07]
x = arange(len(data))
ax = subplot(111)
bar(x, data)
xticks( x + 0.5, ("Windows\nXP", "Windows\n7", "Windows\nVista",
"MacOS X", "iOS", "Linux") )
title("Usage share of web client operating systems: May 2011")
ylabel("Percent Usage")
savefig('barplot.png',format='png')
I have stolen most of the code from an example:
http://matplotlib.sourceforge.net/examples/pylab_examples/custom_ticker1.html
I havent figured out how to color the bars differently, does anybody
know how to do this?