SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S




1
(16)
2
(16)
3
(5)
4
(4)
5
(4)
6
(10)
7
(33)
8
(11)
9
(20)
10
(7)
11
(8)
12
(18)
13
(27)
14
(21)
15
(15)
16
(10)
17
(12)
18
(3)
19
(12)
20
(12)
21
(14)
22
(32)
23
(15)
24
(20)
25
(12)
26
(32)
27
(29)
28
(17)
29
(25)
30
(12)
31
(5)

Showing results of 458

<< < 1 .. 5 6 7 8 9 .. 19 > >> (Page 7 of 19)
From: Andrew S. <str...@as...> - 2010年07月23日 15:31:19
On 7/23/10 3:16 PM, Michael Droettboom wrote:
> I've traced this back to revision 7867:
>
> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/branches/v0_99_maint/lib/matplotlib/axes.py?r1=7867&r2=7866&pathrev=7867 
> <http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/branches/v0_99_maint/lib/matplotlib/axes.py?r1=7867&r2=7866&pathrev=7867>
>
> Andrew: I'm sure that change is there for a good reason -- do you 
> remember what it was? I don't just want to revert it. Interestingly, 
> get_clip_on() is True by default, and I'm not sure in what case it's 
> set to False in this context.
Hi Mike,
I don't remember this. But looking back at the commit logs, I see 
"imshow: only apply axes patch clipping if image doesn't clip itself" as 
the original commit message and then a few minutes later I committed the 
test test_imshow_clip() in text_axes.py. It looks like I was responding 
to a bug and/or patch submission. As long as that test still passes, I 
think it's OK to check in your fix. We could also add Tobias' script as 
another test.
-Andrew
From: Benjamin R. <ben...@ou...> - 2010年07月23日 14:40:45
On Fri, Jul 23, 2010 at 3:18 AM, aliko <ali...@gm...> wrote:
> Although the curves now are fitting in the box, the axes data does not
> updated and freezes at some initial values. I'm also reworked example in
> order to use two Y axises one to the left and one at the right. And the
> second plot attached to the right axis is not autoscaled as the first
> does. Those the two things stops me now.
> Any suggestions is highly appreciated!
>
> # -*- coding: utf-8 -*-
> """
> Created on Fri Jul 23 10:53:59 2010
>
> @author: ali
> """
>
> import sys
>
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
> FigureCanvas
>
> from PyQt4 import QtGui
>
> import numpy as np
> import time
>
> ITERS = 1000
>
> class BlitQT(FigureCanvas):
> def __init__(self):
> FigureCanvas.__init__(self, Figure())
> self.figure.subplots_adjust(right=0.75)
>
> self.ax1 = self.figure.add_subplot(111)
> self.ax1.set_ylabel("Func1")
> self.ax2 = self.ax1.twinx()
> self.ax2.set_ylabel("Func2")
>
> self.ax1.grid()
> self.draw()
>
> self.ax1_background = self.copy_from_bbox(self.ax1.bbox)
> self.ax2_background = self.copy_from_bbox(self.ax2.bbox)
> self.cnt = 0
>
> self.x = np.arange(0,2*np.pi,0.01)
> self.line1, = self.ax1.plot(self.x, np.sin(self.x), 'b',
> animated=True)
> self.line2, = self.ax2.plot(self.x, np.cos(self.x), 'r',
> animated=True)
>
> self.tstart = time.time()
> self.startTimer(10)
>
>
> def timerEvent(self, evt):
> y1 = self.x * np.sin(self.x+self.cnt/10.0)
> y2 = np.cos(self.x+self.cnt/10.0) / self.x
> self.ax1.set_ylim(y1.min(), y1.max())
> self.ax2.set_ylim(y2.min(), y2.max())
> self.restore_region(self.ax1_background, bbox=self.ax1.bbox)
> # self.restore_region(self.ax2_background, bbox=self.ax2.bbox)
>
> # update the data
> self.line1.set_ydata(y1)
> self.line2.set_ydata(y2)
> # just draw the animated artist
> self.ax1.draw_artist(self.line1)
> self.ax2.draw_artist(self.line2)
> # just redraw the axes rectangle
> # self.blit(self.ax1.bbox)
> self.blit(self.ax2.bbox)
>
> if self.cnt == 0:
> self.draw()
> if self.cnt==ITERS:
> # print the timing info and quit
> print 'FPS:' , ITERS/(time.time()-self.tstart)
> sys.exit()
> else:
> self.cnt += 1
>
> app = QtGui.QApplication(sys.argv)
> widget = BlitQT()
> widget.show()
>
> sys.exit(app.exec_())
>
>
aliko,
By doing the plot() call at every iteration of the loop, you are causing
conflicts with the blitting code, which is the source of the slowness. You
need to remove the plot() calls you added and move the set_ylim() call to
*before* "self.ax1_background = self.copy_from_bbox(self.ax1.bbox)".
Actually, it probably should also be before the call to "self.draw()".
Here is why. When you create an axes, but have not yet plotted any data,
the limits aren't known. When you copy the background, it is copying
whatever it knows at that time -- which is that it does *not* know the
limits. Then, each call to "restore_region()" restores that information --
including the fact that it doesn't know the limits.
Therefore, if you set the limits *before* drawing the background and copying
it, then restore_region() will then know the proper axes limits and handle
it correctly.
I hope this makes more sense.
Ben Root
From: Michael D. <md...@st...> - 2010年07月23日 13:31:10
BTW -- I think a possible fix may be to do:
 if not im.get_clip_path():
 im.set_clip_path(self.patch)
Mike
On 07/23/2010 09:16 AM, Michael Droettboom wrote:
> I've traced this back to revision 7867:
>
> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/branches/v0_99_maint/lib/matplotlib/axes.py?r1=7867&r2=7866&pathrev=7867 
> <http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/branches/v0_99_maint/lib/matplotlib/axes.py?r1=7867&r2=7866&pathrev=7867>
>
> Andrew: I'm sure that change is there for a good reason -- do you 
> remember what it was? I don't just want to revert it. Interestingly, 
> get_clip_on() is True by default, and I'm not sure in what case it's 
> set to False in this context.
>
> Mike
>
> On 07/23/2010 03:36 AM, Tobias Winchen wrote:
>> Hi,
>>
>> 
>>> On Thursday 22 July 2010 Michael Droettboom wrote:
>>> Which backend are you using?
>>> 
>> I tried this with GTKAgg and Qt4Agg, its was working with 0.99.0 and 0.99.1 on
>> Debian/Squeeze and 0.99.0 on Scientific Linux 5. I first noticed this with
>> 0.99.3 on Debian/Squeeze, but it is the same with with 1.0.0 on Debian/Squeeze
>> and Scientific Linux 5.
>>
>> 
>>> Can you provide a short script that
>>> reproduces the bug?
>>> 
>> This script reproduces the behaviour:
>>
>>
>> import pylab
>> from math import *
>>
>> d = [[1,2],[3,4]]
>>
>> f = pylab.figure()
>> pylab.subplot(111, projection='hammer')
>>
>> pylab.imshow(d, extent=(-pi,pi,-pi/2,pi/2))
>> f.show()
>>
>>
>> It creates the following plot in version 0.99.0
>> http://web.physik.rwth-aachen.de/~winchen/mpl_0990.png
>>
>> and in version 0.99.3
>> http://web.physik.rwth-aachen.de/~winchen/mpl_0993.png
>>
>> Best regards,
>>
>>
>> Tobias
>> 
>>
>>
>> ------------------------------------------------------------------------------
>> This SF.net email is sponsored by Sprint
>> What will you do first with EVO, the first 4G phone?
>> Visit sprint.com/first --http://p.sf.net/sfu/sprint-com-first
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Mat...@li...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>> 
>
>
> -- 
> Michael Droettboom
> Science Software Branch
> Space Telescope Science Institute
> Baltimore, Maryland, USA
-- 
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA
From: Daniele P. <dpa...@ya...> - 2010年07月23日 12:00:59
 I solved the problem and I'm going to explain the solution I used, it 
can be useful for someone.
y data for each series are contained into 2 different arrays, say y1 and 
y2.
The code is the sequent:
if max(y1) > max(y2):
 y_max = max(y1)
else:
 y_max = max(y2)
if min(y1) < min(y2):
 y_min= min(y1)
else:
 y_min = min(y2)
y_upper_limit = y_max+ y_max/10 # to leave some blank space on 
the top
y_lower_limit = y_min + y_min/10 # to leave some blank space on 
the bottom
Then, in your plot, you set ylim(y_lower_limit, y_upper_limit) and 
that's it.
This solution is good because it doesn't depend on the order of 
magnitude of the processed data, while specifying axes manually can give 
some problems for very different data sets.
I hope this message is correctly sent to the mailing list, the procedure 
for answering a message is not so immediate in my opinion.
Then, I subscribed the mailing list, so from the following messages (I 
have some other problems) I will use a different e-mail address.
Bye :)
Il 20/07/2010 22:28, Benjamin Root ha scritto:
> Somehow, this doesn't seem very satisfying. It is almost accidental. 
> There has to be a better way to do this.
>
> Ben Root
>
> 2010年7月20日 Thøger Emil Juul Thorsen <th...@fy... 
> <mailto:th...@fy...>>
>
> One way is to specify the axes manually, e.g. setting:
>
> (with matyplotlib.pyplot importad as plt:)
>
> plt.axis([200, 500, -600, 600])
>
> ...or whatever seems fitting for you, and do that on both of the y
> axes.
> That should align them nicely.
>
> On Sat, 2010年07月17日 at 20:37 +0200, Daniele Padula wrote:
> > Hi everybody,
> > I have a problem with a plot. I attach a figure to be easily
> understandable.
> >
> > As you can see from the figure, I have in the same area a line
> and a bar
> > plot. The problem is that y=0 for right y axis is different with
> respect
> > to left y axis one. I want the two y=0 to be the same.
> >
> > How can i do that?
> >
> > Excuse me for my bad english, I'm italian :)
> >
> > Thanks in advance.
> >
> ------------------------------------------------------------------------------
> > This SF.net email is sponsored by Sprint
> > What will you do first with EVO, the first 4G phone?
> > Visit sprint.com/first <http://sprint.com/first> --
> http://p.sf.net/sfu/sprint-com-first
> > _______________________________________________ Matplotlib-users
> mailing list Mat...@li...
> <mailto:Mat...@li...>
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first <http://sprint.com/first> --
> http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> <mailto:Mat...@li...>
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: j v. <jim...@no...> - 2010年07月23日 11:10:04
Eric Firing wrote:
>>> You can post-process the image with something like ImageMagick.
>>>
>>> Another alternative is to use PIL -- you can grab the matplotlib buffer,
>>> make a PIL image out of it, and use PIL to convert to an 8-bit palleted
>>> image.
>>>
>>> For that matter, you could probably bypass MPL, and use numpy to create
>>> the 8-bit image you want, and PIL to save it as a PNG.
>>>
>>> -Chris
>>>
>>> Thanks much for the helpful information. I will revisit PIL; I tried matplotlib because of other requirements (colorbar, various figure annotations) which did not appear to be readily available in PIL. At this stage, it depends on how important the requirement is to reduce the size of the PNG images.
>>>
>>> 
>> -- jv
>> 
>
> Try optipng:
>
> http://optipng.sourceforge.net/
>
> Here I am running it on a gray-scale image created by mpl; it was 
> generated in such a way that there are only 100 distinct shades of gray.
> You can see that it reduces the file size by quite a bit, converting it 
> from RGBA to grayscale. This is lossless. For this to work, you have 
> to make sure you have no more than 256 distinct colors--they don't have 
> to be gray.
>
> -rw-rw-r-- 1 efiring efiring 8458 2010年07月22日 16:26 grayfig.png
> efiring@manini:~$ optipng grayfig.png
> OptiPNG 0.6.3: Advanced PNG optimizer.
> Copyright (C) 2001-2009 Cosmin Truta.
>
> ** Processing: grayfig.png
> 800x600 pixels, 4x8 bits/pixel, RGB+alpha
> Reducing image to 8 bits/pixel, grayscale
> Input IDAT size = 8352 bytes
> Input file size = 8458 bytes
>
> Trying:
> zc = 9 zm = 8 zs = 0 f = 0		IDAT size = 3721
> zc = 9 zm = 8 zs = 0 f = 5		IDAT size = 3301
> zc = 9 zm = 8 zs = 1 f = 5		IDAT size = 3286
>
> Selecting parameters:
> zc = 9 zm = 8 zs = 1 f = 5		IDAT size = 3286
>
> Output IDAT size = 3286 bytes (5066 bytes decrease)
> Output file size = 3377 bytes (5081 bytes = 60.07% decrease)
>
> efiring@manini:~$ ll grayfig.png
> -rw-rw-r-- 1 efiring efiring 3377 2010年07月22日 16:26 grayfig.png
>
>
> Eric
>
> ------------------------------------------------------------------------------
> 
Thanks much for this information and also for taking the additional time 
to try the optipng tool. It is very helpful.
Since the above mentioned PNG generation is one step in a "near" 
real-time products generation system, I was hoping to avoid the addition 
of another component (i.e., PNG compression) in the stream, but it 
appears unavoidable.
-- jv
From: aliko <ali...@gm...> - 2010年07月23日 08:24:44
Although the curves now are fitting in the box, the axes data does not 
updated and freezes at some initial values. I'm also reworked example in 
order to use two Y axises one to the left and one at the right. And the 
second plot attached to the right axis is not autoscaled as the first 
does. Those the two things stops me now.
Any suggestions is highly appreciated!
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 23 10:53:59 2010
@author: ali
"""
import sys
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
FigureCanvas
from PyQt4 import QtGui
import numpy as np
import time
ITERS = 1000
class BlitQT(FigureCanvas):
 def __init__(self):
 FigureCanvas.__init__(self, Figure())
 self.figure.subplots_adjust(right=0.75)
 self.ax1 = self.figure.add_subplot(111)
 self.ax1.set_ylabel("Func1")
 self.ax2 = self.ax1.twinx()
 self.ax2.set_ylabel("Func2")
 self.ax1.grid()
 self.draw()
 self.ax1_background = self.copy_from_bbox(self.ax1.bbox)
 self.ax2_background = self.copy_from_bbox(self.ax2.bbox)
 self.cnt = 0
 self.x = np.arange(0,2*np.pi,0.01)
 self.line1, = self.ax1.plot(self.x, np.sin(self.x), 'b', 
animated=True)
 self.line2, = self.ax2.plot(self.x, np.cos(self.x), 'r', 
animated=True)
 self.tstart = time.time()
 self.startTimer(10)
 def timerEvent(self, evt):
 y1 = self.x * np.sin(self.x+self.cnt/10.0)
 y2 = np.cos(self.x+self.cnt/10.0) / self.x
 self.ax1.set_ylim(y1.min(), y1.max())
 self.ax2.set_ylim(y2.min(), y2.max())
 self.restore_region(self.ax1_background, bbox=self.ax1.bbox)
# self.restore_region(self.ax2_background, bbox=self.ax2.bbox)
 # update the data
 self.line1.set_ydata(y1)
 self.line2.set_ydata(y2)
 # just draw the animated artist
 self.ax1.draw_artist(self.line1)
 self.ax2.draw_artist(self.line2)
 # just redraw the axes rectangle
# self.blit(self.ax1.bbox)
 self.blit(self.ax2.bbox)
 if self.cnt == 0:
 self.draw()
 if self.cnt==ITERS:
 # print the timing info and quit
 print 'FPS:' , ITERS/(time.time()-self.tstart)
 sys.exit()
 else:
 self.cnt += 1
app = QtGui.QApplication(sys.argv)
widget = BlitQT()
widget.show()
sys.exit(app.exec_())
From: Tobias W. <wi...@ph...> - 2010年07月23日 07:36:21
Hi,
> On Thursday 22 July 2010 Michael Droettboom wrote:
> Which backend are you using? 
I tried this with GTKAgg and Qt4Agg, its was working with 0.99.0 and 0.99.1 on
Debian/Squeeze and 0.99.0 on Scientific Linux 5. I first noticed this with 
0.99.3 on Debian/Squeeze, but it is the same with with 1.0.0 on Debian/Squeeze 
and Scientific Linux 5.
> Can you provide a short script that
> reproduces the bug?
This script reproduces the behaviour:
import pylab 
from math import *
d = [[1,2],[3,4]]
f = pylab.figure()
pylab.subplot(111, projection='hammer')
pylab.imshow(d, extent=(-pi,pi,-pi/2,pi/2))
f.show()
It creates the following plot in version 0.99.0
http://web.physik.rwth-aachen.de/~winchen/mpl_0990.png
and in version 0.99.3
http://web.physik.rwth-aachen.de/~winchen/mpl_0993.png
Best regards,
Tobias
From: aliko <ali...@gm...> - 2010年07月23日 07:21:52
> The problem here is probably with the blitting. You make a copy of the 
> background before plotting the data. Before you plot the data, the axes 
> have no clue what's its limits are supposed to be. In your example, it 
> won't know until you do the plotting. Then when you restore the 
> background, it is restoring the background that never knew the limits.
> 
> I suggest calling ax.set_xlim() and ax.set_ylim() before doing the 
> copy_from_bbox().
> 
> I hope that helps,
> Ben Root
> 
> 
Thank you very much Ben Root for your prompt response and valuable 
assistance! Now I can set the limits using set_ylim. I call it just 
before self.restore_region(...). But I should calculate limits myself in 
order to provide them to that function.
In my case it looks like this:
y1 = np.sin(self.x+self.cnt/10.0)
y2 = (self.x+self.cnt)/50.0
self.ax.set_ylim(min(y1.min(), y2.min()), max(y1.max(), y2.max()))
another way I've discovered is to call plot() function in every step. 
But this approach is little slowly the difference is about 5%.
From: Eric F. <ef...@ha...> - 2010年07月23日 02:32:24
>> You can post-process the image with something like ImageMagick.
>>
>> Another alternative is to use PIL -- you can grab the matplotlib buffer,
>> make a PIL image out of it, and use PIL to convert to an 8-bit palleted
>> image.
>>
>> For that matter, you could probably bypass MPL, and use numpy to create
>> the 8-bit image you want, and PIL to save it as a PNG.
>>
>> -Chris
>>
>> Thanks much for the helpful information. I will revisit PIL; I tried matplotlib because of other requirements (colorbar, various figure annotations) which did not appear to be readily available in PIL. At this stage, it depends on how important the requirement is to reduce the size of the PNG images.
>>
> -- jv
Try optipng:
http://optipng.sourceforge.net/
Here I am running it on a gray-scale image created by mpl; it was 
generated in such a way that there are only 100 distinct shades of gray.
You can see that it reduces the file size by quite a bit, converting it 
from RGBA to grayscale. This is lossless. For this to work, you have 
to make sure you have no more than 256 distinct colors--they don't have 
to be gray.
-rw-rw-r-- 1 efiring efiring 8458 2010年07月22日 16:26 grayfig.png
efiring@manini:~$ optipng grayfig.png
OptiPNG 0.6.3: Advanced PNG optimizer.
Copyright (C) 2001-2009 Cosmin Truta.
** Processing: grayfig.png
800x600 pixels, 4x8 bits/pixel, RGB+alpha
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 8352 bytes
Input file size = 8458 bytes
Trying:
 zc = 9 zm = 8 zs = 0 f = 0		IDAT size = 3721
 zc = 9 zm = 8 zs = 0 f = 5		IDAT size = 3301
 zc = 9 zm = 8 zs = 1 f = 5		IDAT size = 3286
Selecting parameters:
 zc = 9 zm = 8 zs = 1 f = 5		IDAT size = 3286
Output IDAT size = 3286 bytes (5066 bytes decrease)
Output file size = 3377 bytes (5081 bytes = 60.07% decrease)
efiring@manini:~$ ll grayfig.png
-rw-rw-r-- 1 efiring efiring 3377 2010年07月22日 16:26 grayfig.png
Eric
From: Eric F. <ef...@ha...> - 2010年07月23日 02:08:40
On 07/22/2010 03:40 PM, j vickroy wrote:
> Christopher Barker wrote:
>> Jim Vickroy wrote:
>>
>>> The attachment is a simple script that creates a 2D array of unsigned,
>>> 8-bit integers and uses matplotlib to save it as a PNG file.
>>>
>>> Unfortunately, the PNG file is much larger than expected -- apparently
>>> because it is True-Color; on my MS Windows machine, bit depth, for the
>>> file, is listed as 32 rather than the expected 8.
>>>
>>
>>
>>> Can matplotlib be used to accomplish this? If so, could someone direct
>>> me to where this is discussed?
>>>
>>
>> I don't think so directly. MPL uses a 32 bit image buffer internally,
>> and that's what gets saved out in the PNG.
>>
>> You can post-process the image with something like ImageMagick.
>>
>> Another alternative is to use PIL -- you can grab the matplotlib buffer,
>> make a PIL image out of it, and use PIL to convert to an 8-bit palleted
>> image.
>>
>> For that matter, you could probably bypass MPL, and use numpy to create
>> the 8-bit image you want, and PIL to save it as a PNG.
>>
>> -Chris
>>
>> Thanks much for the helpful information. I will revisit PIL; I tried matplotlib because of other requirements (colorbar, various figure annotations) which did not appear to be readily available in PIL. At this stage, it depends on how important the requirement is to reduce the size of the PNG images.
>>
> -- jv
No need to use anything other than matplotlib for generating the 
figure--Chris's main point is that mpl does not provide configuration 
options for saving png files, but you can take such a png file, complete 
with image, colorbar, annotations, whatever, and use pil or ImageMagick 
(and there are probably several additional alternatives) to convert to a 
more compact png format. I took a quick look at the documentation of 
pil and IM, but unfortunately did not see any nice example of this--it 
is not obvious to me how to generate the palette. I suspect it is not 
hard, but it might take a while to figure it out from the docs.
Programs like the following might do what you want:
http://www.libpng.org/pub/png/apps/pngquant.html
http://pngnq.sourceforge.net/
Eric
>>
>>
>>
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: j v. <jim...@no...> - 2010年07月23日 01:41:06
Christopher Barker wrote:
> Jim Vickroy wrote:
> 
>> The attachment is a simple script that creates a 2D array of unsigned, 
>> 8-bit integers and uses matplotlib to save it as a PNG file.
>>
>> Unfortunately, the PNG file is much larger than expected -- apparently 
>> because it is True-Color; on my MS Windows machine, bit depth, for the 
>> file, is listed as 32 rather than the expected 8.
>> 
>
> 
>> Can matplotlib be used to accomplish this? If so, could someone direct 
>> me to where this is discussed?
>> 
>
> I don't think so directly. MPL uses a 32 bit image buffer internally, 
> and that's what gets saved out in the PNG.
>
> You can post-process the image with something like ImageMagick.
>
> Another alternative is to use PIL -- you can grab the matplotlib buffer, 
> make a PIL image out of it, and use PIL to convert to an 8-bit palleted 
> image.
>
> For that matter, you could probably bypass MPL, and use numpy to create 
> the 8-bit image you want, and PIL to save it as a PNG.
>
> -Chris
>
> Thanks much for the helpful information. I will revisit PIL; I tried matplotlib because of other requirements (colorbar, various figure annotations) which did not appear to be readily available in PIL. At this stage, it depends on how important the requirement is to reduce the size of the PNG images.
> 
-- jv
>
>
> 
From: Friedrich R. <fri...@gm...> - 2010年07月22日 23:46:02
2010年7月20日 Tommy Grav <tg...@ma...>:
> I am trying to compile matplotlib for ActiveState 2.7.0.1 - 64bit on mac os x.
> I have installed numpy 1.4.1 and scipy 0.8.0 from source. Compiling matplotlib
> using
>
> sudo make -f make.osx fetch deps mpl_build mpl_install
>
> works fine, but
>
> sudo python setup.py build
>
> yields the error below. Anyone know how to fix this problem?
>
> Cheers
> Tommy
>       freetype2: found, but unknown version (no pkg-config)
>            * WARNING: Could not find 'freetype2' headers in any
>            * of '.', './freetype2'.
This is the culprit, I think when issuing setup.py via the make.osx
script it adds some sugar telling where to find libraries. You have
to add at least '/usr/local' to the list in setupext.py where there is
'darwin' in front.
> OPTIONAL BACKEND DEPENDENCIES
>        libpng: found, but unknown version (no pkg-config)
>            * Could not find 'libpng' headers in any of '.'
Same thing.
> src/ft2font.h:14:22: error: ft2build.h: No such file or directory
Here you see it clearly. On my system ft2build.h resides in
/usr/local/include, and that is where the make.osx build should put it
too.
> src/ft2font.h:15:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:16:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
blah blah blah
> In file included from src/ft2font.cpp:1:
> src/ft2font.h:33: error: ‘FT_Bitmap’ has not been declared
> src/ft2font.h:33: error: ‘FT_Int’ has not been declared
blah blah blah .......
> src/ft2font.h:33: error: ‘FT_Int’ has not been declared
> src/ft2font.h:89: error: expected ‘,’ or ‘...’ before ‘&’ token
> src/ft2font.h:89: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
> src/ft2font.h:95: error: expected ‘,’ or ‘...’ before ‘&’ token
> src/ft2font.h:95: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
> src/ft2font.h:137: error: ‘FT_Face’ does not name a type
> src/ft2font.h:138: error: ‘FT_Matrix’ does not name a type
> src/ft2font.h:139: error: ‘FT_Vector’ does not name a type
> src/ft2font.h:140: error: ‘FT_Error’ does not name a type
> src/ft2font.h:141: error: ‘FT_Glyph’ was not declared in this scope
> src/ft2font.h:141: error: template argument 1 is invalid
> src/ft2font.h:141: error: template argument 2 is invalid
> src/ft2font.h:142: error: ‘FT_Vector’ was not declared in this scope
> src/ft2font.h:142: error: template argument 1 is invalid
> src/ft2font.h:142: error: template argument 2 is invalid
> src/ft2font.h:148: error: ‘FT_BBox’ does not name a type
> src/ft2font.cpp:45: error: ‘FT_Library’ does not name a type
> src/ft2font.cpp:108: error: variable or field ‘draw_bitmap’ declared void
> src/ft2font.cpp:108: error: ‘FT_Bitmap’ was not declared in this scope
> src/ft2font.cpp:108: error: ‘bitmap’ was not declared in this scope
> src/ft2font.cpp:109: error: ‘FT_Int’ was not declared in this scope
> src/ft2font.cpp:110: error: ‘FT_Int’ was not declared in this scope
> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:1187: warning: ‘int _import_array()’ defined but not used
> cc1plus: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++
> In file included from src/ft2font.cpp:1:
> src/ft2font.h:14:22: error: ft2build.h: No such file or directory
Again.
> src/ft2font.h:15:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:16:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:17:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:18:10: error: #include expects "FILENAME" or <FILENAME>
> src/ft2font.h:19:10: error: #include expects "FILENAME" or <FILENAME>
> In file included from src/ft2font.cpp:1:
> src/ft2font.h:33: error: ‘FT_Bitmap’ has not been declared
> src/ft2font.h:33: error: ‘FT_Int’ has not been declared
> src/ft2font.h:33: error: ‘FT_Int’ has not been declared
> src/ft2font.h:89: error: expected ‘,’ or ‘...’ before ‘&’ token
> src/ft2font.h:89: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
> src/ft2font.h:95: error: expected ‘,’ or ‘...’ before ‘&’ token
> src/ft2font.h:95: error: ISO C++ forbids declaration of ‘FT_Face’ with no type
> src/ft2font.h:137: error: ‘FT_Face’ does not name a type
> src/ft2font.h:138: error: ‘FT_Matrix’ does not name a type
> src/ft2font.h:139: error: ‘FT_Vector’ does not name a type
> src/ft2font.h:140: error: ‘FT_Error’ does not name a type
> src/ft2font.h:141: error: ‘FT_Glyph’ was not declared in this scope
> src/ft2font.h:141: error: template argument 1 is invalid
> src/ft2font.h:141: error: template argument 2 is invalid
> src/ft2font.h:142: error: ‘FT_Vector’ was not declared in this scope
> src/ft2font.h:142: error: template argument 1 is invalid
> src/ft2font.h:142: error: template argument 2 is invalid
> src/ft2font.h:148: error: ‘FT_BBox’ does not name a type
> src/ft2font.cpp:45: error: ‘FT_Library’ does not name a type
> src/ft2font.cpp:108: error: variable or field ‘draw_bitmap’ declared void
> src/ft2font.cpp:108: error: ‘FT_Bitmap’ was not declared in this scope
> src/ft2font.cpp:108: error: ‘bitmap’ was not declared in this scope
> src/ft2font.cpp:109: error: ‘FT_Int’ was not declared in this scope
> src/ft2font.cpp:110: error: ‘FT_Int’ was not declared in this scope
> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:1187: warning: ‘int _import_array()’ defined but not used
> lipo: can't figure out the architecture type of: /var/tmp//cc1zVbyh.out
> error: command 'gcc' failed with exit status 1
sure, it fails with bailing out after such a bunch of errors. But it
tries hard to compile even without proper include files doesn't it :-)
Friedrich
From: Friedrich R. <fri...@gm...> - 2010年07月22日 23:24:08
2010年7月20日 Søren Nielsen <sor...@gm...>:
> Hi,
>
> I'm creating a stand alone program on my mac with OSX 10.4 and it seems to
> work great on it. However, if I transfer my program to a snow leopard (10.6)
> mac, I get the error:
>
> dlopen(/Volumes/KINGSTON/Mac/RAW.app/Contents/Resources/lib/python2.6/matplotlib/ft2font.so,
> 2): Symbol not found: _FT_Load_Glyph
>    Referenced from:
> /Volumes/KINGSTON/Mac/RAW.app/Contents/Resources/lib/python2.6/matplotlib/ft2font.so
>   Expected in: dynamic lookup
This looks to me like a compiler issue, but I'm not 100% sure either.
My guess is that your /opt/local/lib/libfreetype.6.dylib is compiled
for 10.6, i.e., using gcc-4.2, but your matplotlib files shipped with
your .app are compiled with gcc-4.0, as usual on 10.4. I don't know
why py2app doesn't pick up the files in /opt to ship it with your app,
I mean, noone can expect other users to have MacPorts installed when
they run your app. Maybe it's also some precedence issue, but I'm
neither a MacPorts nor a py2app expert :-(
It's good that you provide directly the otool info:
> /opt/local/lib/libfreetype.6.dylib (compatibility version 11.0.0, current
> version 11.0.0)
I guess the following indents/non-indents are unintentional and are
without meaning.
>     /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current
> version 1.2.4)
>     /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current
> version 7.4.0)
>     /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
> version 88.3.3)
>
> /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
> (compatibility version 1.0.0, current version 18.0.0)
>
> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
> (compatibility version 1.0.0, current version 22.0.0)
>     /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current
> version 1.0.0)
>     /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version
> 47.1.0)
hth so far,
Friedrich
From: Christopher B. <Chr...@no...> - 2010年07月22日 23:16:19
Jim Vickroy wrote:
> The attachment is a simple script that creates a 2D array of unsigned, 
> 8-bit integers and uses matplotlib to save it as a PNG file.
> 
> Unfortunately, the PNG file is much larger than expected -- apparently 
> because it is True-Color; on my MS Windows machine, bit depth, for the 
> file, is listed as 32 rather than the expected 8.
> Can matplotlib be used to accomplish this? If so, could someone direct 
> me to where this is discussed?
I don't think so directly. MPL uses a 32 bit image buffer internally, 
and that's what gets saved out in the PNG.
You can post-process the image with something like ImageMagick.
Another alternative is to use PIL -- you can grab the matplotlib buffer, 
make a PIL image out of it, and use PIL to convert to an 8-bit palleted 
image.
For that matter, you could probably bypass MPL, and use numpy to create 
the 8-bit image you want, and PIL to save it as a PNG.
-Chris
-- 
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
From: Aman T. <ama...@gm...> - 2010年07月22日 17:49:30
Sorry, that was a silly question. I just set the clip_on to True to fix
this.
On Thu, Jul 22, 2010 at 1:45 PM, Aman Thakral <ama...@gm...>wrote:
> Hi all,
>
> The text draws outside the plotting area when you zoom in. Sample code is
> attached. To re-create the issue, just use the zoom rect function on the
> plot.
>
> Is there a way to fix this?
>
> Thanks,
> Aman
>
-- 
Aman Thakral
B.Eng & Biosci, M.Eng Design
From: Benjamin R. <ben...@ou...> - 2010年07月22日 17:11:22
On Thu, Jul 22, 2010 at 3:30 AM, aliko <ali...@gm...> wrote:
> Could please anyone help me to get axises autoscaling in following
> example? I took it from the examples and slightly modified it to remove
> all unecessary things trying to make it as short as possible.
>
> Thanks in advance!
>
> import sys
>
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
> FigureCanvas
>
> from PyQt4 import QtGui
>
> import numpy as np
> import time
>
> class BlitQT(FigureCanvas):
> def __init__(self):
> FigureCanvas.__init__(self, Figure())
>
> self.ax = self.figure.add_subplot(111)
> self.ax.grid()
> self.draw()
>
> self.ax_background = self.copy_from_bbox(self.ax.bbox)
> self.cnt = 0
>
> self.x = np.arange(0,2*np.pi,0.01)
> self.sin_line, = self.ax.plot(self.x, np.sin(self.x),
> animated=True)
> self.cos_line, = self.ax.plot(self.x, np.cos(self.x),
> animated=True)
>
> self.tstart = time.time()
> self.startTimer(10)
>
> def timerEvent(self, evt):
> self.restore_region(self.ax_background, bbox=self.ax.bbox)
>
> # update the data
> self.sin_line.set_ydata(np.sin(self.x+self.cnt/10.0))
> self.cos_line.set_ydata((self.x+self.cnt)/50.0)
> # just draw the animated artist
> self.ax.draw_artist(self.sin_line)
> self.ax.draw_artist(self.cos_line)
> # just redraw the axes rectangle
> self.blit(self.ax.bbox)
>
> if self.cnt == 0:
> self.draw()
> self.cnt += 1
>
> app = QtGui.QApplication(sys.argv)
> widget = BlitQT()
> widget.show()
>
> sys.exit(app.exec_())
>
>
>
The problem here is probably with the blitting. You make a copy of the
background before plotting the data. Before you plot the data, the axes
have no clue what's its limits are supposed to be. In your example, it
won't know until you do the plotting. Then when you restore the background,
it is restoring the background that never knew the limits.
I suggest calling ax.set_xlim() and ax.set_ylim() before doing the
copy_from_bbox().
I hope that helps,
Ben Root
From: Michael D. <md...@st...> - 2010年07月22日 16:58:39
Which backend are you using? Can you provide a short script that 
reproduces the bug?
Mike
On 07/22/2010 11:18 AM, Tobias Winchen wrote:
> Dear all,
>
> in matplotlib version 0.99.0 when drawing images with imshow into figures with
> hammer or aitoff axes the images are clipped to the axes. Now this has changed
> in and the images are drawn also outside the axes (version 0.99.3) or not
> drawn at all (version 1.0.0). How can I clip them again to the axes?
>
> Best regards,
>
> Tobias
>
> 
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
From: Tobias W. <wi...@ph...> - 2010年07月22日 15:18:31
Dear all,
in matplotlib version 0.99.0 when drawing images with imshow into figures with 
hammer or aitoff axes the images are clipped to the axes. Now this has changed 
in and the images are drawn also outside the axes (version 0.99.3) or not 
drawn at all (version 1.0.0). How can I clip them again to the axes?
Best regards,
Tobias
From: Jenna L. <je...@as...> - 2010年07月22日 15:17:14
No, I don't think the issue is a flip in the y-axis. I have a number
of different examples of this, and many in which the contour is an
ellipse so I can tell that the overall positioning is correct. It
seems like something is going wrong only when I save the image...
Thanks for the suggestion though!
Jenna
On Wed, Jul 21, 2010 at 3:40 PM, Jenna Lemonias
<je...@as...>wrote <je...@as...%3Ewrote>:
> I am trying to save a matplotlib 2d array image with an overlaid contour as
> an eps file. The contour appears to be shifted with respect to the image
> underneath in the eps file, particularly when I zoom in on the image. This
> shift is not noticeable in the plot within matplotlib.
>
> I am using imshow to display the image. The contour is created by plotting
> a list of closely-spaced x,y coordinates. The attached file matplotlib.png
> is a screenshot of the (zoomed-in) image as displayed by matplotlib. The
> attached file epsfile.png is a screenshot of the (zoomed-in) eps file. When
> I save this image as an eps file, it is actually 1 of 20 subplots and the
> shift is noticeable in each subplot.
>
> Thanks in advance for your help!
>
> Jenna
>
>
Just as a wild guess, could this actually be an issue with how imshow uses
the upper-left corner for (0,0)? I have seen 1-pixel shifts before, but
this shift is a little dramatic and I am left wondering if what we are
really seeing is that the contour that is desired should actually be fliped
in the y-axis?
Maybe you could try another example where you try to draw a contour further
away from the center of the image and see if it still goes in the spot you
expect it to be?
Ben Root
From: mdekauwe <mde...@gm...> - 2010年07月22日 14:34:41
Hi Jeff,
That sounds like the perfect solution as I do have the lat, lons - I'll give
that a go!
Thanks again,
Martin
Jeff Whitaker wrote:
> 
> On 7/22/10 8:08 AM, mdekauwe wrote:
>> Hi Jeff,
>>
>> Yes you are right! Apologies. Whilst it is easy enough to define the grid
>> in
>> this case as it is a regular lat,long grid. If it was for example a
>> geostationary grid, I think this might be more difficult. Is there a way
>> to
>> return the grid for example from the basemap call, which can then be used
>> in
>> the contour call?
>>
>> I hope that makes sense.
>>
>> Thanks again.
> 
> If you have the lats and lons of the data grid, you can convert to map 
> projection coordinates by calling the Basemap instance, i.e.
> 
> map = Basemap(....)
> x,y = map(lons,lats)
> 
> you can then use the x,y values in contour
> 
> map.contourf(x,y,data)
> 
> Does that help?
> 
> -Jeff
> 
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/Basemap-%2B-contour-layer--tp29235080p29237609.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Jeff W. <js...@fa...> - 2010年07月22日 14:30:20
On 7/22/10 8:08 AM, mdekauwe wrote:
> Hi Jeff,
>
> Yes you are right! Apologies. Whilst it is easy enough to define the grid in
> this case as it is a regular lat,long grid. If it was for example a
> geostationary grid, I think this might be more difficult. Is there a way to
> return the grid for example from the basemap call, which can then be used in
> the contour call?
>
> I hope that makes sense.
>
> Thanks again.
If you have the lats and lons of the data grid, you can convert to map 
projection coordinates by calling the Basemap instance, i.e.
map = Basemap(....)
x,y = map(lons,lats)
you can then use the x,y values in contour
map.contourf(x,y,data)
Does that help?
-Jeff
From: mdekauwe <mde...@gm...> - 2010年07月22日 14:08:49
Hi Jeff,
Yes you are right! Apologies. Whilst it is easy enough to define the grid in
this case as it is a regular lat,long grid. If it was for example a
geostationary grid, I think this might be more difficult. Is there a way to
return the grid for example from the basemap call, which can then be used in
the contour call? 
I hope that makes sense.
Thanks again.
 
Jeff Whitaker wrote:
> 
> On 7/22/10 7:48 AM, mdekauwe wrote:
>> import numpy as np
>> from mpl_toolkits.basemap import Basemap
>> import matplotlib.pyplot as plt
>>
>> # generate some random data - i.e. what would be an image of the world,
>> say
>> different
>> # land covers
>> data = np.random.randint(10,27,100*67).reshape(100, 67)
>>
>> # I want to draw a boundary round each land cover type, so
>> # classify a new array
>> data2 = np.where(data == 10, 1, data)
>> data2 = np.where(data == 11, 1, data)
>> data2 = np.where(data == 13, 2, data)
>> data2 = np.where(data == 14, 2, data)
>> data2 = np.where(data == 15, 2, data)
>> data2 = np.where(data == 16, 2, data)
>> data2 = np.where(data == 18, 3, data)
>> data2 = np.where(data == 19, 3, data)
>> data2 = np.where(data == 20, 3, data)
>> data2 = np.where(data == 26, 4, data)
>> data2 = np.where(data == 27, 4, data)
>>
>> plt.contour(data2)
>> plt.show()
>> sys.exit()
>>
>> this pops up a contour plot...
>>
>> Now what if as I do I want to overlay this on a basemap plot...
>>
>> import numpy as np
>> from mpl_toolkits.basemap import Basemap
>> import matplotlib.pyplot as plt
>>
>> # generate some random data - i.e. what would be an image of the world,
>> say
>> different
>> # land covers
>> data = np.random.randint(10,27,100*67).reshape(100, 67)
>>
>> # I want to draw a boundary round each land cover type, so
>> # classify a new array
>> data2 = np.where(data == 10, 1, data)
>> data2 = np.where(data == 11, 1, data)
>> data2 = np.where(data == 13, 2, data)
>> data2 = np.where(data == 14, 2, data)
>> data2 = np.where(data == 15, 2, data)
>> data2 = np.where(data == 16, 2, data)
>> data2 = np.where(data == 18, 3, data)
>> data2 = np.where(data == 19, 3, data)
>> data2 = np.where(data == 20, 3, data)
>> data2 = np.where(data == 26, 4, data)
>> data2 = np.where(data == 27, 4, data)
>>
>> fig = plt.figure(figsize=(8, 6))
>> m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5,
>> resolution='c', projection='cyl')
>> ax = fig.add_axes([0.1, 0.1, 0.6, 0.7])
>> m.ax = ax
>>
>> delta = 0.03
>> x = np.arange(1.5, 3.5, delta)
>> y = np.arange(10.5, 13.5, delta)
>> X, Y = np.meshgrid(x, y)
>>
>> im = m.imshow(data, interpolation='nearest', cmap=plt.cm.jet)
>> m.contour(data2, X, Y, color='black')
>> 
> 
> Martin: This needs to be
> 
> m.contour(X, Y, data2, colors='black')
> 
> (the data goes after the coordinate arrays, and the keyword is 'colors',
> not 'color')
> 
> 
> -Jeff
> 
> 
>> plt.show()
>>
>> This only plots the basemap without the contours?
>>
>> Many thanks,
>>
>> Martin
>>
>>
>> 
> 
> 
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/Basemap-%2B-contour-layer--tp29235080p29237306.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Jeff W. <js...@fa...> - 2010年07月22日 14:01:08
On 7/22/10 7:48 AM, mdekauwe wrote:
> import numpy as np
> from mpl_toolkits.basemap import Basemap
> import matplotlib.pyplot as plt
>
> # generate some random data - i.e. what would be an image of the world, say
> different
> # land covers
> data = np.random.randint(10,27,100*67).reshape(100, 67)
>
> # I want to draw a boundary round each land cover type, so
> # classify a new array
> data2 = np.where(data == 10, 1, data)
> data2 = np.where(data == 11, 1, data)
> data2 = np.where(data == 13, 2, data)
> data2 = np.where(data == 14, 2, data)
> data2 = np.where(data == 15, 2, data)
> data2 = np.where(data == 16, 2, data)
> data2 = np.where(data == 18, 3, data)
> data2 = np.where(data == 19, 3, data)
> data2 = np.where(data == 20, 3, data)
> data2 = np.where(data == 26, 4, data)
> data2 = np.where(data == 27, 4, data)
>
> plt.contour(data2)
> plt.show()
> sys.exit()
>
> this pops up a contour plot...
>
> Now what if as I do I want to overlay this on a basemap plot...
>
> import numpy as np
> from mpl_toolkits.basemap import Basemap
> import matplotlib.pyplot as plt
>
> # generate some random data - i.e. what would be an image of the world, say
> different
> # land covers
> data = np.random.randint(10,27,100*67).reshape(100, 67)
>
> # I want to draw a boundary round each land cover type, so
> # classify a new array
> data2 = np.where(data == 10, 1, data)
> data2 = np.where(data == 11, 1, data)
> data2 = np.where(data == 13, 2, data)
> data2 = np.where(data == 14, 2, data)
> data2 = np.where(data == 15, 2, data)
> data2 = np.where(data == 16, 2, data)
> data2 = np.where(data == 18, 3, data)
> data2 = np.where(data == 19, 3, data)
> data2 = np.where(data == 20, 3, data)
> data2 = np.where(data == 26, 4, data)
> data2 = np.where(data == 27, 4, data)
>
> fig = plt.figure(figsize=(8, 6))
> m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5,
> resolution='c', projection='cyl')
> ax = fig.add_axes([0.1, 0.1, 0.6, 0.7])
> m.ax = ax
>
> delta = 0.03
> x = np.arange(1.5, 3.5, delta)
> y = np.arange(10.5, 13.5, delta)
> X, Y = np.meshgrid(x, y)
>
> im = m.imshow(data, interpolation='nearest', cmap=plt.cm.jet)
> m.contour(data2, X, Y, color='black')
> 
Martin: This needs to be
m.contour(X, Y, data2, colors='black')
(the data goes after the coordinate arrays, and the keyword is 'colors', not 'color')
-Jeff
> plt.show()
>
> This only plots the basemap without the contours?
>
> Many thanks,
>
> Martin
>
>
> 
From: Benjamin R. <ben...@ou...> - 2010年07月22日 13:54:41
On Wed, Jul 21, 2010 at 3:40 PM, Jenna Lemonias <je...@as...>wrote:
> I am trying to save a matplotlib 2d array image with an overlaid contour as
> an eps file. The contour appears to be shifted with respect to the image
> underneath in the eps file, particularly when I zoom in on the image. This
> shift is not noticeable in the plot within matplotlib.
>
> I am using imshow to display the image. The contour is created by plotting
> a list of closely-spaced x,y coordinates. The attached file matplotlib.png
> is a screenshot of the (zoomed-in) image as displayed by matplotlib. The
> attached file epsfile.png is a screenshot of the (zoomed-in) eps file. When
> I save this image as an eps file, it is actually 1 of 20 subplots and the
> shift is noticeable in each subplot.
>
> Thanks in advance for your help!
>
> Jenna
>
>
Just as a wild guess, could this actually be an issue with how imshow uses
the upper-left corner for (0,0)? I have seen 1-pixel shifts before, but
this shift is a little dramatic and I am left wondering if what we are
really seeing is that the contour that is desired should actually be fliped
in the y-axis?
Maybe you could try another example where you try to draw a contour further
away from the center of the image and see if it still goes in the spot you
expect it to be?
Ben Root
From: mdekauwe <mde...@gm...> - 2010年07月22日 13:49:01
Ok... how about this?
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# generate some random data - i.e. what would be an image of the world, say
different
# land covers
data = np.random.randint(10,27,100*67).reshape(100, 67)
# I want to draw a boundary round each land cover type, so 
# classify a new array
data2 = np.where(data == 10, 1, data)
data2 = np.where(data == 11, 1, data)
data2 = np.where(data == 13, 2, data)
data2 = np.where(data == 14, 2, data)
data2 = np.where(data == 15, 2, data)
data2 = np.where(data == 16, 2, data)
data2 = np.where(data == 18, 3, data)
data2 = np.where(data == 19, 3, data)
data2 = np.where(data == 20, 3, data)
data2 = np.where(data == 26, 4, data)
data2 = np.where(data == 27, 4, data)
plt.contour(data2)
plt.show()
sys.exit()
this pops up a contour plot...
Now what if as I do I want to overlay this on a basemap plot...
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# generate some random data - i.e. what would be an image of the world, say
different
# land covers
data = np.random.randint(10,27,100*67).reshape(100, 67)
# I want to draw a boundary round each land cover type, so 
# classify a new array
data2 = np.where(data == 10, 1, data)
data2 = np.where(data == 11, 1, data)
data2 = np.where(data == 13, 2, data)
data2 = np.where(data == 14, 2, data)
data2 = np.where(data == 15, 2, data)
data2 = np.where(data == 16, 2, data)
data2 = np.where(data == 18, 3, data)
data2 = np.where(data == 19, 3, data)
data2 = np.where(data == 20, 3, data)
data2 = np.where(data == 26, 4, data)
data2 = np.where(data == 27, 4, data)
fig = plt.figure(figsize=(8, 6))
m = Basemap(llcrnrlon=1.5, llcrnrlat=10.5, urcrnrlon=3.5, urcrnrlat=13.5, 
 resolution='c', projection='cyl')
ax = fig.add_axes([0.1, 0.1, 0.6, 0.7])
m.ax = ax
delta = 0.03
x = np.arange(1.5, 3.5, delta) 
y = np.arange(10.5, 13.5, delta)
X, Y = np.meshgrid(x, y)
im = m.imshow(data, interpolation='nearest', cmap=plt.cm.jet)
m.contour(data2, X, Y, color='black')
plt.show()
This only plots the basemap without the contours?
Many thanks,
Martin
-- 
View this message in context: http://old.nabble.com/Basemap-%2B-contour-layer--tp29235080p29237074.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
19 messages has been excluded from this view by a project administrator.

Showing results of 458

<< < 1 .. 5 6 7 8 9 .. 19 > >> (Page 7 of 19)
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /