By the way, I had done the chart differently to begin with. But this code
requires more lines, more imports, and is more complex. (Without
plt.gca().yaxis or the formatter, the graph will not come out.)

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FuncFormatter
from matplotlib.ticker import MaxNLocator
defects = [32, 22, 15, 5, 2]
labels = ['vertical', 'horizontal', 'behind', 'left area', 'other']
the_sum = sum(defects)
the_cumsum = np.cumsum(defects)
ind = np.arange(len(defects))
width = .98
x = ind + .5 * width
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
rects = ax1.bar(ind, defects, width=width)
ax1.set_ylim(ymax=the_sum)
ax2.set_ylim(ymax=the_sum)
plt.gca().yaxis.set_major_locator( MaxNLocator(nbins = 6) )
line, = ax2.plot(x, the_cumsum)
ax1.set_xticks(ind+ .5 * width)
ax1.set_xticklabels(labels)
def to_percent(x, pos):
    return round(x/the_sum, 1) * 100
formatter = FuncFormatter(to_percent)
ax2.yaxis.set_major_formatter(formatter)
ax1.set_ylabel('Defects')
ax2.set_ylabel('Percentage')
plt.show()


On Mon, Sep 24, 2012 at 8:50 PM, Paul Tremblay <paulhtremb...@gmail.com>wrote:

>  I took my example from the matplotlib pages itself:
>
> http://matplotlib.org/examples/api/fahrenheit_celcius_scales.html
>
> If you know a better way, please show me.
>
> P.
>
>
> On 9/24/12 4:40 PM, Benjamin Root wrote:
>
>
>
> On Mon, Sep 24, 2012 at 12:21 AM, Paul Tremblay 
> <paulhtremb...@gmail.com>wrote:
>
>> Here is my example of a Pareto chart.
>>
>> For an explanation of a Pareto chart:
>>
>> http://en.wikipedia.org/wiki/Pareto_chart
>>
>> Could I get this chart added to the matplolib gallery?
>>
>>
>> Thanks
>>
>> Paul
>>
>>
> Your code looks overly complicated.  You shouldn't have to be doing the
> connection to the ylim_changed event, I don't think.  I think your main
> problem is that you are calling ax1.plot instead of ax2.plot.
>
> I am not against adding more examples to the gallery, but this would have
> to be cleaned up before it gets included.
>
> Ben Root
>
>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to