changes to plot after py2exe and resizing

sorry, the last email did not get the pic attached. retrying, and text
recopied below:

matplotlib_confusion.jpg

···

Using Python 2.5, wxPython 2.8.4.2 (msw-unicode) matplotlib 0.90.1
on winXP. I have two questions:

  1. I have a small working app that produces a matplotlib plot.
    This is a plot embedded in wxPython (it’s not using Pylab).
    When it is run as a python script, it looks fine. However, after
    packaging it into an .exe with py2exe (using GUI2Exe to do that),
    the font and size of the axes are different: smaller, and now in

italics. See attached picture. I also get the errors:

C:\mycode\dist\myapp.exe\matplotlib_init_.py:948: UserWarning: Could not find matplotlibrc; using defaults
C:\mycode\dist\myapp.exe\matplotlib_init_.py:999: UserWarning: could not find rc file; returning defaults

I did include in the data files this folder:
C:\Python25\Lib\site-packages\matplotlib\mpl-data\back.png

and in the Python packages I included:
pytz
matplotlib.numerix

  1. I thought that was the only error, but now I also see that, in
    either case (as a python script or as a .exe file), each time I
    resize the window, and the plot resizes (it is in a wxPython
    sizer), the color of the data line changes randomly! It starts
    blue, and then as I resize it it can be green, red, whatever.
    In the picture attached, with resizing they’ve wound up different
    colors, though they both started blue as they should have.

Any ideas?
Thanks.

s

sorry, the last email did not get the pic attached. retrying, and text
recopied below:
----------------------------------------------

Using Python 2.5, wxPython 2.8.4.2 (msw-unicode) matplotlib 0.90.1
on winXP. I have two questions:

1) I have a small working app that produces a matplotlib plot.
This is a plot embedded in wxPython (it's not using Pylab).
When it is run as a python script, it looks fine. However, after
packaging it into an .exe with py2exe (using GUI2Exe to do that),
the font and size of the axes are different: smaller, and now in
italics. See attached picture. I also get the errors:

C:\mycode\dist\myapp.exe\matplotlib\__init__.py:948: UserWarning: Could not
find matplotlibrc; using defaults
C:\mycode\dist\myapp.exe\matplotlib\__init__.py:999: UserWarning: could not
find rc file; returning defaults

I did include in the data files this folder:
C:\Python25\Lib\site-packages\matplotlib\mpl-data\back.png

and in the Python packages I included:
pytz
matplotlib.numerix

2) I thought that was the only error, but now I also see that, in
either case (as a python script or as a .exe file), each time I
resize the window, and the plot resizes (it is in a wxPython
sizer), the color of the data line changes randomly! It starts
blue, and then as I resize it it can be green, red, whatever.
In the picture attached, with resizing they've wound up different
colors, though they both started blue as they should have.

My guess is that you are calling plot in an event handler that is
triggered by a resize, and are seeing mpl's color cycler. As for the
fonts, it looks like whatever fonts are being picked up by default
(outside of py2exe) are not being packaged by py2exe. Make sure all
the fonts in site-pacakges/matplotlib/mpl-data are being picked up by
py2exe. In general, as long as py2exe is picking up all of mpl-data,
I don't see why you would have trouble with fonts, your rc file, or
your icons (eg back.png). Of course, w/o seeing any code or setup
files this is just a wild guess.

JDH

···

On Nov 15, 2007 10:42 PM, C M <cmpython@...287...> wrote:

The font problem turned out to be simply that I didn’t realize that the
latest version of matplotlib comes with the matplotlibrc file commented out
(I had not tried to change fonts before so hadn’t noticed I couldn’t).
Uncommented the fonts section solved it. Thanks for the tip.

Is there a way to disable color cycling?

cm

···

On Nov 16, 2007 9:23 AM, John Hunter <jdh2358@…287…> wrote:

s

On Nov 15, 2007 10:42 PM, C M <cmpython@…287…> wrote:

sorry, the last email did not get the pic attached. retrying, and text

recopied below:

Using Python 2.5, wxPython 2.8.4.2 (msw-unicode) matplotlib 0.90.1
on winXP. I have two questions:

  1. I have a small working app that produces a matplotlib plot.
    This is a plot embedded in wxPython (it’s not using Pylab).
    When it is run as a python script, it looks fine. However, after

packaging it into an .exe with py2exe (using GUI2Exe to do that),
the font and size of the axes are different: smaller, and now in
italics. See attached picture. I also get the errors:

C:\mycode\dist\myapp.exe\matplotlib_init_.py:948: UserWarning: Could not
find matplotlibrc; using defaults
C:\mycode\dist\myapp.exe\matplotlib_init_.py:999: UserWarning: could not
find rc file; returning defaults

I did include in the data files this folder:
C:\Python25\Lib\site-packages\matplotlib\mpl-data\back.png

and in the Python packages I included:
pytz
matplotlib.numerix

  1. I thought that was the only error, but now I also see that, in
    either case (as a python script or as a .exe file), each time I
    resize the window, and the plot resizes (it is in a wxPython

sizer), the color of the data line changes randomly! It starts
blue, and then as I resize it it can be green, red, whatever.
In the picture attached, with resizing they’ve wound up different

colors, though they both started blue as they should have.

My guess is that you are calling plot in an event handler that is
triggered by a resize, and are seeing mpl’s color cycler. As for the

fonts, it looks like whatever fonts are being picked up by default
(outside of py2exe) are not being packaged by py2exe. Make sure all
the fonts in site-pacakges/matplotlib/mpl-data are being picked up by
py2exe. In general, as long as py2exe is picking up all of mpl-data,

I don’t see why you would have trouble with fonts, your rc file, or
your icons (eg back.png). Of course, w/o seeing any code or setup
files this is just a wild guess.

JDH

Well, you could explicitly provide the color to "plot" but this is
masking a deeper problem. You do not want to e callng "plot" on every
window redraw event. If you post a code snippet, we might be able to
help.

JDH

···

On Nov 17, 2007 12:26 AM, C M <cmpython@...287...> wrote:

The font problem turned out to be simply that I didn't realize that the
latest version of matplotlib comes with the matplotlibrc file commented out
(I had not tried to change fonts before so hadn't noticed I couldn't).
Uncommented the fonts section solved it. Thanks for the tip.

Is there a way to disable color cycling?

Yeah, I believe that was what was happening. In trying to learn to embed plots
in wx I started from an example (“Matplotlib figure in a wx panel”) found [

here](http://www.scipy.org/Matplotlib_figure_in_a_wx_panel),
and for some reason in that example the figure is calls a draw() method only
on an idle following each resize, which ultimately calls “plot”. I’m not sure why it
is done like that. I instead now put the draw() method just under the init,
so it is drawn once initially and resized accordingly, and it works better now.
No color changing, and in fact there had been a problem with the font getting
distorted after a few resizes (no idea what that was about) that is now gone too.
Very good.

Thanks very much on both issues.
CM

···

On Nov 17, 2007 7:59 AM, John Hunter <jdh2358@…287…> wrote:

On Nov 17, 2007 12:26 AM, C M <cmpython@…287…> wrote:

The font problem turned out to be simply that I didn’t realize that the
latest version of matplotlib comes with the matplotlibrc file commented out

(I had not tried to change fonts before so hadn’t noticed I couldn’t).
Uncommented the fonts section solved it. Thanks for the tip.

Is there a way to disable color cycling?

Well, you could explicitly provide the color to “plot” but this is
masking a deeper problem. You do not want to e callng “plot” on every
window redraw event. If you post a code snippet, we might be able to

help.

JDH

I was trying the covert my program into .exe file using py2exe.

I got this message:

File "pylab.pyc", line 1, in <module>
File "matplotlib\__init__.pyc", line 733, in <module>
File "matplotlib\__init__.pyc", line 273, in wrapper
File "matplotlib\__init__.pyc", line 360, in _get_data_path
RuntimeError: Could not find the matplotlib data files

Has anyone seen this before, how to solve this problem?

Thanks

Xiaoshan