Histogram and changing x-axis limits

Histogram and changing x-axis limits
Hi -

I’m using the following code to generate a histogram. I also want to plot the Upper Control Limit as a vertical line to the right of the histogram bars and a Lower Control Limit to the left of the bars. Each Control Limit would be represented by a vertical line. The code below does not include the line necessary to plot a sample control limit.

the histogram of the data

n, bins, patches = matplotlib.matlab.hist(histogram_data, 10, normed=0)

add a ‘best fit’ line

y = matplotlib.matlab.normpdf(bins, average[i], std_dev[i])

l = matplotlib.matlab.plot(bins, y, ‘r–’)

matplotlib.matlab.set(l, ‘linewidth’, 2)

matplotlib.matlab.set(matplotlib.matlab.gca(), ‘xlim’, [199, 205])

matplotlib.matlab.xlabel(DataDescription[i])

matplotlib.matlab.ylabel(‘Number of Parts’)

matplotlib.matlab.title(PartNum + " – " + PartDesc)

matplotlib.matlab.show()

When I modify the code with the additional line to plot a Lower Control Limit:

the histogram of the data

n, bins, patches = matplotlib.matlab.hist(histogram_data, 10, normed=0)

add a ‘best fit’ line

y = matplotlib.matlab.normpdf(bins, average[i], std_dev[i])

l = matplotlib.matlab.plot(bins, y, ‘r–’)

matplotlib.matlab.set(l, ‘linewidth’, 2)

matplotlib.matlab.set(matplotlib.matlab.gca(), ‘xlim’, [199, 205])

matplotlib.matlab.xlabel(DataDescription[i])

matplotlib.matlab.ylabel(‘Number of Parts’)

matplotlib.matlab.plot([201,201],[0,40],‘k–’) <— added this line to plot a control limit

matplotlib.matlab.title(PartNum + " – " + PartDesc)

matplotlib.matlab.show()

The x-axis limits are somehow automatically forced to something less than that specified in the line: matplotlib.matlab.set(matplotlib.matlab.gca(), ‘xlim’, [199, 205]). The histogram appears as would be expected, but now I cannot see my Control Limit (specified in the added line of code) as it seems to be plotted off of the chart.

If I comment out the additional line (that plotted a vertical line as a control limit), the x-axis limits return to normal, as expected (199 -> 205).

Why are the x-axis limits adjusted when I try to plot a vertical line as a Control Limit?

Thanks in advance,

Dave Engelsma