On Wed, Aug 11, 2010 at 8:43 AM, Tony S Yu <tsy...@gmail.com> wrote:
>
> On Aug 11, 2010, at 6:56 AM, Rob Schneider wrote:
>
>>
>> I extract data out of a database (via Django and Python).  I'm drawing two 
>> bar charts.  One is a stacked bar, and one is a simple bar.
>> The code for each graph is in their own function.  I call the function to 
>> draw the graph sequencially (in function "CreateAllWebSite() below).
>>
>> Problem is that when I do this, the graph called second comes out all 
>> jumbled.  See attached copies of png files.  If I swap the function calls, 
>> always first is ok and the the second one is jumbled.  If I call them one at 
>> a time, they both work just fine (which is how i developed the second).  
>> once put together, the second is wrong.  For example, the legend from the 
>> first graph gets put on the second graph . The x-axis for the second is all 
>> jumbled at the bottom left corner of the graph instead of along the x-axis 
>> properly.
>>
>> I'm using Matplotlib 0.98.5.3 on OS X.  I will upgrade to 1.0 of Matplot lib 
>> soon.
>>
>> I suspect some sort of memory issue; perhaps caused by how I import 
>> matplotlib in the global section of the python program; but far as I can 
>> tell this is correct, or is it?  I suspect memory as how else would legend 
>> from the first graph get put on the second graph? Is there some sort of 
>> reset function to call to clear out the old graph? I sort of thought that 
>> calling a completely different function would cover that.
>>
>> Here's the code extract with portions I think no relevant snipped out. From 
>> debugging I'm confident the number arrays holding the data is ok.  As I 
>> said, when producing the graphs one at a time, it work fine.  So that code 
>> snipped out below.
>>
>> #!/usr/bin/env python
>> # -*- coding: UTF-8 -*-
>>
>> import matplotlib
>> matplotlib.use('Agg') # before importing pyplot per docs
>> import matplotlib.pyplot as plt
>> import numpy as np
>>
>> [snipped the import of Python and Django libraries]
>>
>> ###########################################################
>> def CreateAllWebSite():
>>  # here is the one function that calls the two graphing functions 
>> sequentially.
>>  # whichever of these is called first is done fine.  Second flawed.  calling 
>> one at at time, each works ok
>>  CreateMemberStatFigure()
>>  CreateMemberStatCategoryFigure()
>> ###############################################
>> def CreateMemberStatFigure():
>> # this function creates a stacked bar chart
>> [snipped out portions where arrays created]
>
> Hi Rob,
>
> It would be helpful if you could provide a runnable example. I know it's a 
> pain, but you should simplify your example so that it's runnable with only 
> matplotlib and numpy You should create some fake data to replace these 
> portions that you've cut out. Plus there are some (Django?) 
> classes/functions/globals that are undefined.
>

Agreed. The only thing I can think of is that the second figure is
reusing the first. You can try calling plt.figure() at the beginning
of the functions to create a new figure, or call plt.figure() in
between the calls to CreateMemberStatCategoryFigure() and
CreateMemberStatFigure(). I can't be sure since you didn't include the
code that actually calls these functions.

Ryan


-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to