On 9/26/12 12:31 PM, Benjamin Root wrote:


On Wed, Sep 26, 2012 at 12:10 PM, Paul Tremblay <paulhtremb...@gmail.com <mailto:paulhtremb...@gmail.com>> wrote:

    Thanks. I know when doing 8/9 in python 2.x you get 0. With python
    3 you get a decimal (Hooray, Python 3!).

    I ran the script I submitted with python 3. Do I need to change
    the defects and totals from integers to floats to make my chart
    work universally?

    P.


Here is my latest version of the Pareto chart. If the developers feel it is worthy, then they can include it in the gallery. Otherwise, it will have to remain in these threads, useful when, needing such a chart, someone searches the web and ends up here.

import matplotlib.pyplot as plt
import numpy as np

# the data to plot
defects = [32.0, 22.0, 15.0, 5.0, 2.0]
labels = ['vertical', 'horizontal', 'behind', 'left area', 'other']
the_sum = sum(defects) # ie, 32 + 22 + 15 + 5 + 2
the_cumsum = np.cumsum(defects) # 32, 32 + 22, 32 + 22 + 15, 32 + 22 + 15 + 5, 32 + 22, + 15 + 5 + 2
percent = (np.divide(the_cumsum, the_sum)) * 100
ind = np.arange(len(defects))  # the x locations for the groups
width = .98 # with do of the bars, where a width of 1 indidcates no space between bars
x = ind + .5 * width # find the middle of the bar
fig = plt.figure() # create a figure
ax1 = fig.add_subplot(111) # and a subplot
ax2 = ax1.twinx() # create a duplicate y axis
rects1 = ax1.bar(ind, defects, width=width) # draw the chart
line, = ax2.plot(x, percent) # draw the  line
ax1.set_ylim(ymax=the_sum) # without these limits, graphs will not work
ax2.set_ylim(0, 100)
ax1.set_xticks(x) # set ticks for middle of bars
ax1.set_xticklabels(labels) # create the labels for the bars
ax1.set_ylabel('Defects') # create the left y axis label
ax2.set_ylabel('Percentage') # create the right y axis label
plt.show()


------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to