Todd,
I am glad that worked for you.
I am assuming that you are coming from a Matlab-like experience where every
plot command did produced a graphical result when called? If so, I can see
how this behavior can be a little confusing. I will admit I was a little
confused at first when I started using matplotlib, but it turns out that
this is a strength of matplotlib.
Matplotlib has the ability to turn on/off the "interactive mode". If you
imagine that Matlab defaults to interactive mode as 'on', then matplotlib
defaults to 'off'. This way, you can generate all of your plots before
spending time rendering them (and re-rendering them). I have personally
found this to be valuable with pcolor. In Matlab, each subsequent call to a
pcolor figure (for axes labeling, colorbar and such) would require another
re-render of the plot and was very slow on my computer. Matplotlib does not
suffer from this with interactive mode turned off.
Therefore, by default, you should write up your scripts so that you call
"plt.show()" last (even after any savefig() calls) if you wish to have the
figured displayed to the screen. (I know I have seen a statement to this
effect before, but I forget where...).
Anyway, you can always call "plt.ion()" to turn interactive mode on, and
"plt.ioff()" to turn it off, or you can use ipython with the "-pylab"
argument (although I don't know if this is the same as turning interactive
mode on...).
I hope this is informative.
Ben Root
On Mon, Jun 7, 2010 at 10:46 PM, Todd V Rovito <rovit...@gmail.com> wrote:
> Ben,
> That worked great, thanks!!! Just a few points. The documentation
> under the image tutorial section does not specify that a user has to do
> "plt.show()", should I submit a bug report or something? I changed my code
> and listed it below it works as long as I comment out the plot c section.
> In other words if I perform a normal 2d plot then close plot window the
> image plot does not product a result. If I comment out the plot c section
> then the image plot works great. Any ideas?
>
> Even the stink bug example is working when I read a image from disk.
> Thanks.
>
>
> # -*- coding: utf-8 -*-
> from numpy import *
> import matplotlib.pyplot as plt
> import matplotlib.image as mpimg
>
> print "Numpy version: " + __version__
>
> a = array([10,20,30,40])
> print "result of a"
> print a
>
> b = arange(4)
> print "result of b"
> print b
>
> c = linspace(-pi, pi, 30)
> print "result of c"
> print c
>
> # this plot code works
> print "plot c"
> plt.plot(c)
> plt.ylabel("-pi to + pi")
> plt.xlabel("value of c")
> plt.show()
>
> # this image processing code does not work
> print "doing image processing stuff"
> img=mpimg.imread("/Users/rovitotv/Desktop/stinkbug.png") # this does not
> work
> ##img = zeros((10, 10), dtype=uint8)
> ##for i in range(10):
> ## img[i,i] = 255;
>
> plt.imshow(img)
> plt.show()
>
> print "data type of img:"
> print img.dtype
> print "size of img:" + str(img.size)
> print img
>
>
>
> On Mon, Jun 7, 2010 at 10:04 AM, Benjamin Root <ben.r...@ou.edu> wrote:
>
>> Todd,
>>
>> I think you are missing a "plt.show()" at the end of your code.
>> matplotlib, by default on most systems, does not show a plot until you tell
>> it to using plt.show() command.
>>
>> See if that works,
>> Ben Root
>>
>> On Mon, Jun 7, 2010 at 7:57 AM, Todd V Rovito <rovit...@gmail.com>wrote:
>>
>>> Greetings,
>>> I just installed Python 2.6 (python.org), Numpy 1.4.1, and
>>> Matplotlib 0.99.1.2 all on Mac OS X 10.6 in an attempt to learn about
>>> scientific programming in python. Go easy on me since I am a begginer. The
>>> Python and Numpy seem to be working correctly. I can get matplotlib to make
>>> plots but I can't get it to show images. I tried the stinkbug example in
>>> the Matplotlib users guide documentation with no success. Errors are _NOT_
>>> generated but neither are any results on the screen. The imread command
>>> produces a float32 matrix that contains all 1. values so I tried creating my
>>> own uint8 matrix with a diagnoal line. My code is below. Thanks for any
>>> help you can provide.
>>>
>>>
>>>
>>> # -*- coding: utf-8 -*-
>>> from numpy import *
>>> import matplotlib.pyplot as plt
>>> import matplotlib.image as mpimg
>>>
>>> print "Numpy version: " + __version__
>>> a = array([10,20,30,40])
>>> print "result of a"
>>> print a
>>>
>>> b = arange(4)
>>> print "result of b"
>>> print b
>>>
>>> c = linspace(-pi, pi, 30)
>>> print "result of c"
>>> print c
>>>
>>> # this plot code works
>>> print "plot c"
>>> plt.plot(c)
>>> plt.ylabel("-pi to + pi")
>>> plt.xlabel("value of c")
>>> plt.show()
>>>
>>> # this image processing code does not work
>>> print "doing image processing stuff"
>>> # img=mpimg.imread("/Users/rovitotv/Desktop/stinkbug.png") # this does
>>> not work
>>> img = zeros((10, 10), dtype=uint8)
>>> for i in range(10):
>>> img[i,i] = 255;
>>>
>>> plt.imshow(img)
>>> print "data type of img:"
>>> print img.dtype
>>> print "size of img:" + str(img.size)
>>> print img
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> ThinkGeek and WIRED's GeekDad team up for the Ultimate
>>> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
>>> lucky parental unit. See the prize list and enter to win:
>>> http://p.sf.net/sfu/thinkgeek-promo
>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Matplotlib-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> ThinkGeek and WIRED's GeekDad team up for the Ultimate
>> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
>> lucky parental unit. See the prize list and enter to win:
>> http://p.sf.net/sfu/thinkgeek-promo
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users