Unable to make sequential calls to functions with create matplotlib graphs ... second gets jumbled

Running 0.98.5.3
(would upgrade to 1.0 but having trouble installing it on Mac OS X as it doesn't appear to like the version of Python Apple provides).

I have a module where there are two functions which call matplotlib to each create a different graph which both saved to an output PNG file. The import statements:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

are at the top of the module file. Neither function imports anything specifically, relying on the above imports.

I call each function sequentially. The result is that the first graph is created correctly. The second graph is flawed, and in fact shows the legend from the first function. When I reverse the function calls, which ever graphing function is called first is ok, but second is flawed. If I call each function on it's own, within the same Python session, the graphs (both) get produced flawlessly.

both charts are bar charts; but one does a stacked bar and the other is a simple bar chart.

Why would I not be able to call the two functions sequentially? Why does the first call interfere with the second call?

--rms

Running 0.98.5.3
(would upgrade to 1.0 but having trouble installing it on Mac OS X as it doesn't appear to like the version of Python Apple provides).

Standard procedure on the Mac is to install the python from python.org. That way you don't risk fouling up the python that OS X is depending on, and at the same time your own code can use the version of python that most extension packages are built for.

I have a module where there are two functions which call matplotlib to each create a different graph which both saved to an output PNG file. The import statements:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

are at the top of the module file. Neither function imports anything specifically, relying on the above imports.

I call each function sequentially. The result is that the first graph is created correctly. The second graph is flawed, and in fact shows the legend from the first function. When I reverse the function calls, which ever graphing function is called first is ok, but second is flawed. If I call each function on it's own, within the same Python session, the graphs (both) get produced flawlessly.

both charts are bar charts; but one does a stacked bar and the other is a simple bar chart.

Why would I not be able to call the two functions sequentially? Why does the first call interfere with the second call?

I don't think anyone is going to be able to answer this question until you provide a minimal stand-alone code example. Also, the process of stripping your code down to the shortest example that displays the undesired behavior may show you where the problem lies.

Eric

ยทยทยท

On 08/08/2010 12:53 AM, Rob Schneider wrote: