Re: [Matplotlib-users] Wind barb bug

2015-04-27 Thread Jesper Larsen
Hi Tom,

Thanks for the reply. I will open it as an issue on github.

Best regards,
Jesper

2015-04-25 22:20 GMT+02:00 Thomas Caswell tcasw...@gmail.com:

 Jesper,

 Can you open an issue on this on github.  If you are feeling ambitious a
 pull request fixing the bug (as you seem to have a good idea of where the
 problem is) would also be great!

 Tom

 On Fri, Apr 24, 2015 at 8:38 AM Jesper Larsen jesper.webm...@gmail.com
 wrote:

 Hi Matplotlib Users,

 When I make wind barbs with rounding enabled and custom barb increments I
 noticed that there were no wind barbs with half barbs above 2 full barbs.
 The reason seems to be a bug in the _find_tails method. The bug is
 illustrated by this small script (_find_tails is a copy of the one in
 matplotlib):

 import numpy as np

 def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
 '''
 Find how many of each of the tail pieces is necessary.  Flag
 specifies the increment for a flag, barb for a full barb, and half for
 half a barb. Mag should be the magnitude of a vector (ie. = 0).

 This returns a tuple of:

 (*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)

 *half_flag* is a boolean whether half of a barb is needed,
 since there should only ever be one half on a given
 barb. *empty_flag* flag is an array of flags to easily tell if
 a barb is empty (too low to plot any barbs/flags.
 '''

 #If rounding, round to the nearest multiple of half, the smallest
 #increment
 if rounding:
 mag = half * (mag / half + 0.5).astype(np.int)

 num_flags = np.floor(mag / flag).astype(np.int)
 mag = np.mod(mag, flag)

 num_barb = np.floor(mag / full).astype(np.int)
 mag = np.mod(mag, full)

 half_flag = mag = half
 empty_flag = ~(half_flag | (num_flags  0) | (num_barb  0))

 return num_flags, num_barb, half_flag, empty_flag

 def main():
 mag = np.arange(0,21,1)
 barb_incs = {'half': 2.57222,
  'full': 5.1,
  'flag': 25.7222}
 print 'With rounding'
 num_flags, num_barb, half_flag, empty_flag =  _find_tails(None, mag,
 rounding=True, **barb_incs)
 for i in range(len(mag)):
 print mag[i], num_flags[i], num_barb[i], half_flag[i],
 empty_flag[i]
 print 'Without rounding'
 num_flags, num_barb, half_flag, empty_flag =  _find_tails(None, mag,
 rounding=False, **barb_incs)
 for i in range(len(mag)):
 print mag[i], num_flags[i], num_barb[i], half_flag[i],
 empty_flag[i]

 if __name__ == '__main__':
 exit(main())

 It seems like the error is not present when the barb increments are not
 set. I believe the reason for the bug is the float comparison (half_flag =
 mag = half) where the value is rounded to a value very close to/identical
 to the 'half' increment. And it seems like python does the right thing when
 the half increment is a whole number but not always when it is not.

 But in any case the code should probably not depend two floats being
 equal.

 Best regards,
 Jesper

 --
 One dashboard for servers and applications across Physical-Virtual-Cloud
 Widest out-of-the-box monitoring support with 50+ applications
 Performance metrics, stats and reports that give you Actionable Insights
 Deep dive visibility with transaction tracing using APM Insight.
 http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Wind barb bug

2015-04-24 Thread Jesper Larsen
Hi Matplotlib Users,

When I make wind barbs with rounding enabled and custom barb increments I
noticed that there were no wind barbs with half barbs above 2 full barbs.
The reason seems to be a bug in the _find_tails method. The bug is
illustrated by this small script (_find_tails is a copy of the one in
matplotlib):

import numpy as np

def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
'''
Find how many of each of the tail pieces is necessary.  Flag
specifies the increment for a flag, barb for a full barb, and half for
half a barb. Mag should be the magnitude of a vector (ie. = 0).

This returns a tuple of:

(*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)

*half_flag* is a boolean whether half of a barb is needed,
since there should only ever be one half on a given
barb. *empty_flag* flag is an array of flags to easily tell if
a barb is empty (too low to plot any barbs/flags.
'''

#If rounding, round to the nearest multiple of half, the smallest
#increment
if rounding:
mag = half * (mag / half + 0.5).astype(np.int)

num_flags = np.floor(mag / flag).astype(np.int)
mag = np.mod(mag, flag)

num_barb = np.floor(mag / full).astype(np.int)
mag = np.mod(mag, full)

half_flag = mag = half
empty_flag = ~(half_flag | (num_flags  0) | (num_barb  0))

return num_flags, num_barb, half_flag, empty_flag

def main():
mag = np.arange(0,21,1)
barb_incs = {'half': 2.57222,
 'full': 5.1,
 'flag': 25.7222}
print 'With rounding'
num_flags, num_barb, half_flag, empty_flag =  _find_tails(None, mag,
rounding=True, **barb_incs)
for i in range(len(mag)):
print mag[i], num_flags[i], num_barb[i], half_flag[i], empty_flag[i]
print 'Without rounding'
num_flags, num_barb, half_flag, empty_flag =  _find_tails(None, mag,
rounding=False, **barb_incs)
for i in range(len(mag)):
print mag[i], num_flags[i], num_barb[i], half_flag[i], empty_flag[i]

if __name__ == '__main__':
exit(main())

It seems like the error is not present when the barb increments are not
set. I believe the reason for the bug is the float comparison (half_flag =
mag = half) where the value is rounded to a value very close to/identical
to the 'half' increment. And it seems like python does the right thing when
the half increment is a whole number but not always when it is not.

But in any case the code should probably not depend two floats being equal.

Best regards,
Jesper
--
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Antialiasing colorbars

2014-09-30 Thread Jesper Larsen
Hi matplotlib users,

Is it possible to disable antialiasing for a colorbar? If not directly is
it the possible to postprocess the axes instance to se antialiasing for
relevant elements?

The reason I am asking is because I would like to produce a paletted png
(using PIL) of the colorbar without the risk of removing any important
colors in the process (in essence the output from matplotlib needs to have
less than 256 colors for this to work).

Best regards,
Jesper
--
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Wind barbs with small arrow heads

2014-09-17 Thread Jesper Larsen
Hi matplotlib users

I am developing an application for showing weather forecasts using
matplotlib. We use wind barbs for displaying wind forecasts:

http://api.fcoo.dk/ifm-maps/greenland/?zoom=6lat=62lon=-45layer=FCOO%20Standardoverlays=TTFFF

This is fine for our power users. We do however also have some users who
are not used to wind barbs. I have elsewhere seen people put a small arrow
head at the foot of the wind barbs to make it more clear which direction
the wind blows toward.

As far as I can see from the matplotlib quiver.py code this is not possible
with matplotlib. But the _make_barbs method does not seem that complicated
so I wondered if it is something that I can do myself. I have however never
used the matplotlib low level drawing primitives. I would therefore
appreciate any good advice.

Best regards,
Jesper Baasch-Larsen
--
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Bug in contourf or BoundaryNorm?

2014-03-28 Thread Jesper Larsen
Hi matplotlib users,

I believe the normalization behaviour is wrong for contourf at least when
using a BoundaryNorm. In the script below I am using the same norm to plot
the same data using contourf and pcolormesh. The color should change around
an x value of 0.15 but it is shifted somewhat for contourf. I do realize
that the pcolormesh is in principle shifted a little - but with a grid
spacing of 0.001 that should not matter. Please see the example script
below.

Best regards,
Jesper


Test inconsistent normalization behaviour for matplotlib

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import from_levels_and_colors

# Make custom colormap and norm
levs = [0.0, 0.1, 0.2]
cols = [[0.00392156862745098, 0.23137254901960785, 0.07450980392156863],
[0.00392156862745098, 0.49019607843137253, 0.15294117647058825]]
extend = 'neither'
cmap, norm = from_levels_and_colors(levs, cols, extend)

# Setup testdata
a = np.arange(0.05, 0.15, 0.001, dtype=np.float_)
a, b = np.meshgrid(a, a)
plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False)
plt.savefig('contourf.png')
plt.clf()
plt.pcolormesh(a, b, a, norm=norm, cmap=cmap, antialiased=False)
plt.savefig('pcolormesh.png')
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Bug in contourf or BoundaryNorm?

2014-03-28 Thread Jesper Larsen
Hi Ian

Thanks for your reply and help. I see your point. I guess it is only the
BoundaryNorm where it would make sense to have contourf use the boundary
levels from the norm. In my real problem described by the above example I
have long forgotten the levs variable when I arrive at the contourf point.
I will therefore instead just use levels=norm.boundaries.

Best regards,
Jesper


2014-03-28 15:17 GMT+01:00 Ian Thomas ianthoma...@gmail.com:

 On 28 March 2014 12:56, Jesper Larsen jesper.webm...@gmail.com wrote:

 I believe the normalization behaviour is wrong for contourf at least when
 using a BoundaryNorm. In the script below I am using the same norm to plot
 the same data using contourf and pcolormesh. The color should change around
 an x value of 0.15 but it is shifted somewhat for contourf. I do realize
 that the pcolormesh is in principle shifted a little - but with a grid
 spacing of 0.001 that should not matter. Please see the example script
 below.

 Best regards,
 Jesper

 
 Test inconsistent normalization behaviour for matplotlib
 
 import numpy as np
 import matplotlib.pyplot as plt
 from matplotlib.colors import from_levels_and_colors

 # Make custom colormap and norm
 levs = [0.0, 0.1, 0.2]
 cols = [[0.00392156862745098, 0.23137254901960785, 0.07450980392156863],
 [0.00392156862745098, 0.49019607843137253, 0.15294117647058825]]
 extend = 'neither'
 cmap, norm = from_levels_and_colors(levs, cols, extend)

 # Setup testdata
 a = np.arange(0.05, 0.15, 0.001, dtype=np.float_)
 a, b = np.meshgrid(a, a)0
 plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False)
 plt.savefig('contourf.png')
 plt.clf()
 plt.pcolormesh(a, b, a, norm=norm, cmap=cmap, antialiased=False)
 plt.savefig('pcolormesh.png')


 Jesper,

 Regardless of whether you specify a colormap and norm, if you want
 contourf to calculate contours at particular levels
 then you need to specify those levels.  If you don't then contourf will
 choose the levels for you, and in your case these are chosen to be
 [0.045  0.06   0.075  0.09   0.105  0.12   0.135  0.15 ]
 which is why you see the color transition at x=0.105.

 To fix this, change your contourf line from
 plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False)
 to
 plt.contourf(a, b, a, norm=norm, cmap=cmap, antialiased=False, levels=levs)
 and you will get exactly what you want.

 Ian

--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Matplotlib for tiles - blank lines

2014-03-24 Thread Jesper Larsen
Hi matplotlib users,

I am using matplotlib to produce plots (tiles) in a Web Map Service.
Unfortunately I cannot get Matplotlib to plot on the entire image. There
are one transparent (pixel) line at the bottom and one transparent line at
the right. This is of course a problem when the tiles are shown in a map.
Please see example below. Can anyone see what I am doing wrong?

Best regards,
Jesper

import numpy as np
import matplotlib as mpl
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

w = 256
h = 256
dpi = 128
figsize = w/dpi, h/dpi
fig = Figure(figsize=figsize, dpi=dpi, frameon=False)
canvas = FigureCanvas(fig)
ax = fig.add_axes([0, 0, 1, 1])

x = np.arange(0, 10, 0.1)
y = np.arange(10, 20, 0.2)
X, Y = np.meshgrid(x, y)
D = np.ones((X.shape[0]-1, X.shape[1]-1))
V = np.linspace(0.0, 1.0, 10)
ax.pcolor(X, Y, D, antialiased=False)
ax.axis( [x[0], x[-1], y[0], y[-1]] )
ax.axis('off')
filename = 'testfile.png'
fig.savefig(filename, dpi=128)

# Test image
from PIL import Image
im = Image.open(filename)
print im.getcolors()
--
Learn Graph Databases - Download FREE O'Reilly Book
Graph Databases is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib for tiles - blank lines

2014-03-24 Thread Jesper Larsen
Thanks Pierre,

from __future__ import division did not help me, I am using mpl 1.1.1rc. I
will try upgrading to a newer version of mpl and report back whether that
helps. My output is:

[(511, (255, 255, 255, 0)), (65025, (0, 0, 128, 255))]

Best regards,
Jesper



2014-03-24 11:27 GMT+01:00 Pierre Haessig pierre.haes...@crans.org:

 Hi,

 Le 24/03/2014 10:45, Jesper Larsen a écrit :
  I am using matplotlib to produce plots (tiles) in a Web Map Service.
  Unfortunately I cannot get Matplotlib to plot on the entire image.
  There are one transparent (pixel) line at the bottom and one
  transparent line at the right. This is of course a problem when the
  tiles are shown in a map. Please see example below. Can anyone see
  what I am doing wrong?
 I've run your code and got no transparent pixels.

 print im.getcolors()
 [(65536, (0, 0, 128, 255))]

 I also tried with __future__ division to see if there was something with
 figsize = w/dpi, h/dpi, but got the same output

 best,
 Pierre

 (python 2.7 on Linux, mpl 1.3.1)



 --
 Learn Graph Databases - Download FREE O'Reilly Book
 Graph Databases is the definitive new guide to graph databases and their
 applications. Written by three acclaimed leaders in the field,
 this first edition is now available. Download your free book today!
 http://p.sf.net/sfu/13534_NeoTech
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Learn Graph Databases - Download FREE O'Reilly Book
Graph Databases is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib for tiles - blank lines

2014-03-24 Thread Jesper Larsen
Hi Nicolas,

Then everything is transparent. I have no .matplotlibrc file. I pulled the
most recent version of mpl. And that solved the issue.

Best regards,
Jesper



2014-03-24 12:09 GMT+01:00 Nicolas Rougier nicolas.roug...@inria.fr:



 If you do not draw at all (no pcolor call), do you still get transparent
 colors ?
 If yes, what is your .matplotlibrc ?


 Nicolas


 On 24 Mar 2014, at 11:49, Jesper Larsen jesper.webm...@gmail.com wrote:

  Thanks Pierre,
 
  from __future__ import division did not help me, I am using mpl 1.1.1rc.
 I will try upgrading to a newer version of mpl and report back whether that
 helps. My output is:
 
  [(511, (255, 255, 255, 0)), (65025, (0, 0, 128, 255))]
 
  Best regards,
  Jesper
 
 
 
  2014-03-24 11:27 GMT+01:00 Pierre Haessig pierre.haes...@crans.org:
  Hi,
 
  Le 24/03/2014 10:45, Jesper Larsen a écrit :
   I am using matplotlib to produce plots (tiles) in a Web Map Service.
   Unfortunately I cannot get Matplotlib to plot on the entire image.
   There are one transparent (pixel) line at the bottom and one
   transparent line at the right. This is of course a problem when the
   tiles are shown in a map. Please see example below. Can anyone see
   what I am doing wrong?
  I've run your code and got no transparent pixels.
 
  print im.getcolors()
  [(65536, (0, 0, 128, 255))]
 
  I also tried with __future__ division to see if there was something with
  figsize = w/dpi, h/dpi, but got the same output
 
  best,
  Pierre
 
  (python 2.7 on Linux, mpl 1.3.1)
 
 
 
 --
  Learn Graph Databases - Download FREE O'Reilly Book
  Graph Databases is the definitive new guide to graph databases and
 their
  applications. Written by three acclaimed leaders in the field,
  this first edition is now available. Download your free book today!
  http://p.sf.net/sfu/13534_NeoTech
  ___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 
 
 --
  Learn Graph Databases - Download FREE O'Reilly Book
  Graph Databases is the definitive new guide to graph databases and
 their
  applications. Written by three acclaimed leaders in the field,
  this first edition is now available. Download your free book today!
 
 http://p.sf.net/sfu/13534_NeoTech___
  Matplotlib-users mailing list
  Matplotlib-users@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Learn Graph Databases - Download FREE O'Reilly Book
Graph Databases is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib for tiles - blank lines

2014-03-24 Thread Jesper Larsen
Hi Phil,

Yes, I can confirm that upgrading fixes the issue. Thanks for the pointer
to cartopy.

Best regards,
Jesper




2014-03-24 12:13 GMT+01:00 Phil Elson pelson@gmail.com:

 I fixed an issue related to this (I too was producing map tiles) in
 matplotlib v1.2 I believe.

 The original issue can be found at
 https://github.com/matplotlib/matplotlib/pull/1591 and so I suggest this
 might not be an issue with matplotlib = v1.3.

 Incidentally, if you are producing map tiles you might be interested in
 cartopy which will allow you to produce properly referenced geo maps (and
 therefore tiles) with coastlines etc.
 I've put a short-sh example in a gist () with the rendered results also
 available (https://rawgithub.com/pelson/9738051/raw/map.html). I've also
 got a tornado based handler version which generates the tiles upon HTTP
 request rather than storing the tiles on disk (much more efficient if you
 have highly dynamic data and a caching layer).

 Let me know if updating your matplotlib version helps,

 Cheers,

 Phil







 On 24 March 2014 09:45, Jesper Larsen jesper.webm...@gmail.com wrote:

 Hi matplotlib users,

 I am using matplotlib to produce plots (tiles) in a Web Map Service.
 Unfortunately I cannot get Matplotlib to plot on the entire image. There
 are one transparent (pixel) line at the bottom and one transparent line at
 the right. This is of course a problem when the tiles are shown in a map.
 Please see example below. Can anyone see what I am doing wrong?

 Best regards,
 Jesper

 import numpy as np
 import matplotlib as mpl
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as
 FigureCanvas

 w = 256
 h = 256
 dpi = 128
 figsize = w/dpi, h/dpi
 fig = Figure(figsize=figsize, dpi=dpi, frameon=False)
 canvas = FigureCanvas(fig)
 ax = fig.add_axes([0, 0, 1, 1])

 x = np.arange(0, 10, 0.1)
 y = np.arange(10, 20, 0.2)
 X, Y = np.meshgrid(x, y)
 D = np.ones((X.shape[0]-1, X.shape[1]-1))
 V = np.linspace(0.0, 1.0, 10)
 ax.pcolor(X, Y, D, antialiased=False)
 ax.axis( [x[0], x[-1], y[0], y[-1]] )
 ax.axis('off')
 filename = 'testfile.png'
 fig.savefig(filename, dpi=128)

 # Test image
 from PIL import Image
 im = Image.open(filename)
 print im.getcolors()



 --
 Learn Graph Databases - Download FREE O'Reilly Book
 Graph Databases is the definitive new guide to graph databases and their
 applications. Written by three acclaimed leaders in the field,
 this first edition is now available. Download your free book today!
 http://p.sf.net/sfu/13534_NeoTech
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
Learn Graph Databases - Download FREE O'Reilly Book
Graph Databases is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] pcolorfast antialiasing

2014-03-20 Thread Jesper Larsen
Hi matplotlib users,

I am currently performing some experiments with plotting in matplotlib for
at web application. One thing I have noticed is that my image test sizes
are reduced by a factor 4.5 when not using antialiasing. And that for
pcolormesh the time it takes to produce a plot without antialiasing is
approximately half the time it takes to produce one with. And for my
application I do not really need antialiasing when the cost is so large.

I was therefore wondering whether it is possible to disable antialiasing
for pcolorfast? Otherwise I guess I will stick with pcolormesh and contourf.

Best regards,
Jesper
--
Learn Graph Databases - Download FREE O'Reilly Book
Graph Databases is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Saving figure instance for reuse

2012-08-15 Thread Jesper Larsen
Hi Matplotlib users

I have an application where performance is critical and matplotlib is
the performance bottleneck. I am making a lot of figures using the
same basic setup of the figure. And from my profiling I can see that
this basic setup accounts for most of the CPU time. Let us say that I
make a given figure including some axes. My questions are:

1. Can I make a copy of this figure including axes (copy.deepcopy does
not work on Figure objects) and use the copy for plotting on?

2. And how? Should I use the frozen method somehow?

I did do something similar some years back. But at the time I removed
the stuff I had drawn on the figure. I would like to avoid this for
two reasons: 1) Thread safety, I must be able to draw figures in
several simultaneous threads and 2) I really had to go into some
low-level details in matplotlib (not a show-stopper, but for
maintenance reasons I would like to keep the code as clear as
possible).

Best regards,
Jesper

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Reducing png file size

2009-05-17 Thread Jesper Larsen
Hi mpl-users,

I have a web application in which I produce png files using
matplotlib. Unfortunately the files are quite big (up to ~300 kb). I
have however tried using the Linux tool pngnq to reduce the file size
with a factor ~3-4 with almost no degradation of the result. I
therefore wondered whether it is possible to setup matplotlib to do
something similar (from the source code the savefig method for png
files does not seem to use any keyword arguments). Here is the output
of the command pnginfo for the matplotlib output file and the pngnq
processed file:

0.0.0.0.0.0.20090517t00z.768.png...
  Image Width: 768 Image Length: 328
  Bitdepth (Bits/Sample): 8
  Channels (Samples/Pixel): 4
  Pixel depth (Pixel Depth): 32
  Colour Type (Photometric Interpretation): RGB with alpha channel
  Image filter: Single row per byte filter
  Interlacing: No interlacing
  Compression Scheme: Deflate method 8, 32k window
  Resolution: 5039, 5039 (pixels per meter)
  FillOrder: msb-to-lsb
  Byte Order: Network (Big Endian)
  Number of text strings: 0 of 0
  Offsets: 0, 0

0.0.0.0.0.0.20090517t00z.768-nq8.png...
  Image Width: 768 Image Length: 328
  Bitdepth (Bits/Sample): 8
  Channels (Samples/Pixel): 1
  Pixel depth (Pixel Depth): 8
  Colour Type (Photometric Interpretation): PALETTED COLOUR (256
colours, 0 transparent)
  Image filter: Single row per byte filter
  Interlacing: No interlacing
  Compression Scheme: Deflate method 8, 32k window
  Resolution: 0, 0 (unit unknown)
  FillOrder: msb-to-lsb
  Byte Order: Network (Big Endian)
  Number of text strings: 0 of 0
  Offsets: 0, 0

I am not using transparency for anything. For a web application a
reduction from 300 kb to 90 kb is really important so I hope you have
some good ideas. Otherwise I guess I will have to put in a call to
pngnq in my code (although I prefer to avoid calls to external
programs in the Python code when possible).

Best regards,
Jesper

--
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in Agg backend?

2009-04-22 Thread Jesper Larsen
Hi Michael and others,

Sorry for the late answer. I am on Ubuntu 8.10. Unfortunately I have
not had time to look any more into the issue (which might very well be
an error on my part) but I will return when I have more info (I have
made a temporary fix).

I tried using valgrind-massif to reproduce your plot but unfortunately
newer versions of valgrind-massif do not support ps plots.

Best regards,
Jesper

2009/4/15 Michael Droettboom md...@stsci.edu:
 I am not able to reproduce this leak here with 0.98.6svn from today on
 RHEL4.  What platform are you on?

 (See attached massif profile -- the memory usage is flat...)

 Mike

 Jesper Larsen wrote:

 Hi matplotlib developers and users,

 I have had some problems with a memory leak in a long running
 matplotlib based web application that I have developed
 (www.worldwildweather.com). I believe the problem is due to a memory
 leak in the Agg backend but I am not sure. Below is a script which for
 me results in a consistently increasing amount of  memory usage. I am
 using mpl version 0.98.6svn. The problem does not occur when the
 savefig command is commented out. And it does not occur when cs =
 ax.contourf(z) and ax.cla() are moved outside the loop (before and
 after respectively).

 Best regards,
 Jesper

 import os, gc
 import numpy as npy
 import matplotlib as mpl
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as
 FigureCanvas

 def report_memory():
    Report memory.
    gc.collect()
    pid = os.getpid()
    a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
    return int(a2[1].split()[1])

 fig = Figure(dpi=100)
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 FigureCanvas(fig)

 n = 1000
 z = npy.zeros((n,n))
 for i in range(2000):
    cs = ax.contourf(z)
    fig.savefig('test.png')
    ax.cla()
    print report_memory(), i

 I have not pasted in all of the output but just the first and last 25
 lines:
 53356 0
 53360 1
 53360 2
 53360 3
 53360 4
 53360 5
 53360 6
 53360 7
 53360 8
 53360 9
 53360 10
 53360 11
 53360 12
 53360 13
 53360 14
 53360 15
 53360 16
 53360 17
 53356 18
 53360 19
 53360 20
 53360 21
 53360 22
 53360 23
 53356 24
 ...
 57552 1975
 57552 1976
 57552 1977
 57552 1978
 57552 1979
 57552 1980
 57552 1981
 57552 1982
 57552 1983
 57552 1984
 57552 1985
 57552 1986
 57552 1987
 57552 1988
 57552 1989
 57552 1990
 57552 1991
 57552 1992
 57552 1993
 57552 1994
 57552 1995
 57552 1996
 57552 1997
 57552 1998
 57552 1999


 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


 --
 Michael Droettboom
 Science Software Branch
 Operations and Engineering Division
 Space Telescope Science Institute
 Operated by AURA for NASA



--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak in Agg backend?

2009-04-15 Thread Jesper Larsen
Hi matplotlib developers and users,

I have had some problems with a memory leak in a long running
matplotlib based web application that I have developed
(www.worldwildweather.com). I believe the problem is due to a memory
leak in the Agg backend but I am not sure. Below is a script which for
me results in a consistently increasing amount of  memory usage. I am
using mpl version 0.98.6svn. The problem does not occur when the
savefig command is commented out. And it does not occur when cs =
ax.contourf(z) and ax.cla() are moved outside the loop (before and
after respectively).

Best regards,
Jesper

import os, gc
import numpy as npy
import matplotlib as mpl
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

def report_memory():
Report memory.
gc.collect()
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
return int(a2[1].split()[1])

fig = Figure(dpi=100)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
FigureCanvas(fig)

n = 1000
z = npy.zeros((n,n))
for i in range(2000):
cs = ax.contourf(z)
fig.savefig('test.png')
ax.cla()
print report_memory(), i

I have not pasted in all of the output but just the first and last 25 lines:
53356 0
53360 1
53360 2
53360 3
53360 4
53360 5
53360 6
53360 7
53360 8
53360 9
53360 10
53360 11
53360 12
53360 13
53360 14
53360 15
53360 16
53360 17
53356 18
53360 19
53360 20
53360 21
53360 22
53360 23
53356 24
...
57552 1975
57552 1976
57552 1977
57552 1978
57552 1979
57552 1980
57552 1981
57552 1982
57552 1983
57552 1984
57552 1985
57552 1986
57552 1987
57552 1988
57552 1989
57552 1990
57552 1991
57552 1992
57552 1993
57552 1994
57552 1995
57552 1996
57552 1997
57552 1998
57552 1999

--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Localization in mpl

2009-04-08 Thread Jesper Larsen
Hi matplotlib-users,

I have an application which I am currently translating to other
languages including Chinese. I was wondering what recommendations you
have for internationalization with regards to matplotlib. Using the
default font it seems like Chinese characters are not showing up on
the plots. I tried running this file:

# -*- coding: utf-8 -*-
from matplotlib import pyplot as p
p.plot([1,2,4])
wind = u'\u98ce'
p.title(wind)
p.savefig('test.png')

But there is just a box instead of the proper character on the plot.
Any ideas what went wrong? Do I have to use a special font?

I also tried using TeX following the example here:

http://matplotlib.sourceforge.net/examples/pylab_examples/tex_unicode_demo.html

but it did not work when I put in Chinese symbols.

Any ideas?

Best regards,
Jesper

--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Font sizes for web application

2008-12-02 Thread Jesper Larsen
Thank you for your answers and the obvious solution (banging head into wall).

Best regards,
Jesper

2008/12/1 Jae-Joon Lee [EMAIL PROTECTED]:
 On Mon, Dec 1, 2008 at 12:56 AM, Jesper Larsen [EMAIL PROTECTED] wrote:
 Hi Matplotlib users,

 I have a web application in which I would like to scale the plots down
 if the users horizontal screen size is less than 800. Currently only
 the plot is scaled while the fonts are fixed in size (see link below
 for application). This is of course not a viable solution. I was
 therefore wondering what the best way to scale fonts consistently with
 figure size is. A requirement is that the scaling is thread safe (or
 whatever it is called) in the sense that it should not affect other
 threads executing matplotlib (since they may have different screen
 resolutions).


 Saving the figure with smaller dpi doesn't work?
 It is not clear how you're scaling down the over all plot (smaller
 figure size, maybe?),
 but I guess the easiest way is to have everything same and save it
 with a smaller dpi.

 -JJ


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Font sizes for web application

2008-11-30 Thread Jesper Larsen
Hi Matplotlib users,

I have a web application in which I would like to scale the plots down
if the users horizontal screen size is less than 800. Currently only
the plot is scaled while the fonts are fixed in size (see link below
for application). This is of course not a viable solution. I was
therefore wondering what the best way to scale fonts consistently with
figure size is. A requirement is that the scaling is thread safe (or
whatever it is called) in the sense that it should not affect other
threads executing matplotlib (since they may have different screen
resolutions).

As far as I can see the relative font size is not an option since they
seem to be adjusted globally by:

matplotlib.font_manager.set_default_size(size)

If that is true I guess I better calculate the font size each time I
write text to the plot and give it explicitly as an input parameter.
What is your opinion on that?

Best regards,
Jesper

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib or numpy bug?

2008-11-27 Thread Jesper Larsen
Hi Eric and Mauro,

Thanks for your answers.

2008/11/27 Eric Firing [EMAIL PROTECTED]:
 It looks OK to me with mpl and numpy from svn.

I tried upgrading to numpy from svn as well. Unfortunately the problem
persists (I have attached a plot). I have seen the problem on two of
my Ubuntu machines. Maybe it is caused by my specific setup and
supporting libraries.

Since I have a working solution and it does not seem to affect others
(based on a survey of two:-) let us just leave the problem for now. If
someone else encounter it please let me know and I will try to dive a
bit into the issue. If the problem turns up again when I have a need
to upgrade numpy (which is probably when matplotlib requires me to) I
will also look into it.

Best regards,
Jesper
attachment: test1.png-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Matplotlib or numpy bug?

2008-11-26 Thread Jesper Larsen
Hi matplotlib users,

The script below produces weird arrows when using numpy 1.2.1 and
matplotlib trunk. When I reinstall numpy 1.2.0 instead it seems fine.
I use the Agg backend. I am not sure where to start in tracking the
bug down so I will just post the rather sparse information that I
have.

Please let me know if you need any further information from me.

Best regards,
Jesper

import math
import numpy.ma as ma
import pylab as p

a = ma.ones((10,10))
a[:2,:] = ma.masked
a[:,9:] = ma.masked
b = ma.array(-a)
nx, ny = a.shape

for i in range(nx):
  for j in range(ny):
a[i,j] = a[i,j]*math.cos(i*j)
b[i,j] = -b[i,j]*math.sin(i*j)

print a

p.quiver(a,b)
p.grid(True)
p.savefig('test1.png')

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] savefig to StringIO and import into PIL

2008-10-22 Thread Jesper Larsen
Hi mpl users,

I am trying to save a figure to a file like object (a StringIO object)
and load this object into PIL (Python Imaging Library). The code for
this is really simple (fig is my figure object):

# This works
fig.savefig('test.png', format='png')
im = Image.open('test.png')

# This fails
imgdata = StringIO.StringIO()
fig.savefig(imgdata, format='png')
im = Image.open(imgdata)

  File /home/jl/testfile.py, line 551, in contour
im = Image.open(imgdata)
  File /usr/lib/python2.5/site-packages/PIL/Image.py, line 1916, in open
raise IOError(cannot identify image file)
IOError: cannot identify image file

Does anyone know what I am doing wrong? I would really like to avoid
putting the image on disk before opening it in PIL since I am using
the code in a web application where speed is important.

Best regards,
Jesper

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] GTKAgg throwing an exception

2008-10-12 Thread Jesper Larsen
Hi matplotlib-users,

I decided to try to make some plots that I have previously made in png
format using the Agg backend in jpeg format using the GTKAgg backend
(which I guess is the one I should use for this). Unfortunately my
script exits with an error. I have therefore created a simple test
script (test.py) that illustrates the problem (at least on my
computer):

import matplotlib
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as
FigureCanvas

fig = matplotlib.figure.Figure(dpi=100)
canvas = FigureCanvas(fig)
fig.savefig('test.jpg')

When I run it I get:

$ python test.py
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:357:
GtkWarning: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED
(widget) || GTK_IS_INVISIBLE (widget)' failed
  gtk.DrawingArea.realize(self)
/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py:360:
GtkWarning: gdk_pixmap_new: assertion `(drawable != NULL) || (depth !=
-1)' failed
  pixmap = gdk.Pixmap (self.window, width, height)
Traceback (most recent call last):
  File test.py, line 6, in module
fig.savefig('test.jpg')
  File /usr/lib/python2.5/site-packages/matplotlib/figure.py, line
964, in savefig
self.canvas.print_figure(*args, **kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/backend_bases.py,
line 1310, in print_figure
**kwargs)
  File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py,
line 347, in print_jpeg
return self._print_image(filename, 'jpeg')
  File /usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py,
line 360, in _print_image
pixmap = gdk.Pixmap (self.window, width, height)
RuntimeError: could not create GdkPixmap object

I am using matplotlib 0.98.3, pygtk 2.14.0. My system is a Linux Ubuntu:

$ uname -a
Linux blanket out #1 SMP Wed Aug 20 18:39:13 UTC 2008 i686 GNU/Linux

Does anyone know what is wrong?

Best regards,
Jesper

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] PNG performance tips

2008-03-03 Thread Jesper Larsen
Hi Matplotlib users,

I have an application which produces PNG files using the AGG backend.
When I profile the application I can see that much of the cpu time is
spent in the method write_png called by print_figure in backend_agg.py.

Does anyone know which backend is the best for producing fast good
quality PNG files (with fast being as important as good quality)?

In another thread I read that antialiasing could be disabled for better
performance. I tried doing that in each call to contourf and it resulted
in a performance improvement. Does anyone have other performance tips
with regard to PNG files?

Cheers,
Jesper


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] PNG performance tips

2008-03-03 Thread Jesper Larsen
On Mon, 2008-03-03 at 08:16 -0500, Michael Droettboom wrote:
  I have an application which produces PNG files using the AGG backend.
  When I profile the application I can see that much of the cpu time is
  spent in the method write_png called by print_figure in backend_agg.py.
 
 I have seen this myself.  Keep in mind that timing includes a lot of 
 disk I/O, so if your images are particularly large, or you're saving to 
 a network or external disk, or if another process steps in at that 
 moment and wants to read/write to the disk, that could be the 
 bottleneck, more so than just the CPU time spent doing the PNG 
 compression.  On any reasonably modern PC, I suspect that's the case.
 
  Does anyone know which backend is the best for producing fast good
  quality PNG files (with fast being as important as good quality)?
 
 They should all be approximately the same wrt actually writing out the 
 file -- they're all using libpng either directly or indirectly.  It also 
 means there's not much that matplotlib can do to improve its 
 performance, short of submitting patches to libpng -- but I suspect 
 there isn't a lot of long-hanging fruit left to improve in such a 
 widely-used library.

My application is web based. I am therefore considering serving the png files
directly from memory in a future release as outlined here:

http://www.scipy.org/Cookbook/Matplotlib/Matplotlib_and_Zope

Although I am still considering what impacts that will have on my caching of
the plots. I am currently saving the png files and reusing them if the same
plot is requested again - but I am considering pickling individual elements of
the plots instead since there are a lot of plots in which the only differences
is some text (I am already caching parts of the plot in memory). But I don't
know the performance of such a solution yet. I will give you a heads up when I
know (which won't be in the immediate future since I have other things that
are higher up on my to do list).

  In another thread I read that antialiasing could be disabled for better
  performance. I tried doing that in each call to contourf and it resulted
  in a performance improvement. Does anyone have other performance tips
  with regard to PNG files?
 
 Saving to a Python file-like object (if you're doing that) is slower 
 than saving directly to a file path.
 
 See the recent thread on Matplotlib performance for a discussion of 
 decimation of data (if your data set is really large).

I am writing directly to a file path and I have already decimated my data
sets - so that won't help me.

Cheers,
Jesper


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] ytick fontsize for exponentials

2007-11-28 Thread Jesper Larsen
Hi matplotlib users

I am trying to fit a substantial number of subplots into a single plot.
I would therefore like to reduce the font size of my x- and yticks. Some
of the plots contain very large numbers on the y-axis. Using the default
formatting this means that the exponential will be written above the
plot. When the font size of the y-axis is reduced the font size of the
exponential above the plot is not reduced as shown in the example code
below:

import pylab

pylab.figure()
x = [1, 2, 3]
y = [1e13, 2e13, 3e13]
pylab.plot(x,y)
pylab.xticks(fontsize=6)
pylab.yticks(fontsize=6)
pylab.savefig('test.png')

Has anyone got any suggestions on how to reduce the font size of the
exponential as well or is this a bug in matplotlib?

- Jesper

-- 
Jesper Larsen, Ph.D.
Scientist
National Environmental Research Institute 
University of Aarhus
Department of Marine Ecology 
Frederiksborgvej 399 
DK-4000 Roskilde 
Denmark 
tel: +45 46301866
http://www.neri.dk


-
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] basemap covering a small area

2007-07-09 Thread Jesper Larsen
Hi Jeff,

On Friday 06 July 2007 18:28, Jeff Whitaker wrote:
 Jesper:  Hmm, I guess I never thought anyone would make a map that small. 
 I tweaked some of the parameters to make it work better (svn revision
 3470).  Here's the diff in case you just want to apply the patch manually:

Thanks for the patch. And apparantly you were right until now;-) In any case I 
would guess that at some point basemap would need to be changed.

In shelf sea modelling we are now making setups with horizontal resolutions of 
down to the order of hundreds of meters and global ocean models are not far 
from this resolution either:

https://www.navo.navy.mil/nipr_2006/modeling.html

I am not entirely up to date with meteorological models but at least I know of 
one limited area model that I use which has a resolution of 5 km.

 This will make drawing of meridians and parallels slower, however.

What about making the resolution dependent on the size of the map if this is a 
problem? I have a small method that I am using for creating nice contour 
levels - although smarter methods definitely must exist. I have tried to 
adapt it for producing what you need. If you decide to include something like 
this please be aware that the Decimal(str(delta)) should probably be changed 
(I don't think it will handle all cases well). Maybe it is faster simply to 
increase the resolution as you have already done when it becomes necessary:

def _getInterval(minval, maxval, ninter):
  Returns list which resolves minval to maxval with at least ninter 
intervals.
  import decimal
  import numpy as npy

  # Calculate interval between increments
  delta = (maxval-minval)/ninter
  n = decimal.Decimal(str(delta)).adjusted()
  delta = 10**n

  # Round off minimum and maximum values
  xmin = minval/10**n
  xmax = maxval/10**n
  xmin = (xmin - xmin % 10)*10**n
  xmax = (xmax + xmax % 10)*10**n

  values = npy.arange(xmin, xmax+delta, delta)
  return values

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Basemap reuse

2007-06-04 Thread Jesper Larsen
On Friday 01 June 2007 18:52, Jeff Whitaker wrote:
 Jesper:  Here's a better way, that allows you to label the meridians and
 parallels.  It will only work for projection='cyl', although a similar
 solution could be worked up for 'merc' and 'mill'.
snip

Thanks,

I have implemented that solution. The only issue I have discovered so far is 
that I also had to recalculate the aspect ratio of the map (since I use this 
to calculate the figure size):

def resetmapbounds(map,llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat):
map.llcrnrlat = llcrnrlat; map.llcrnrlon = llcrnrlon
map.urcrnrlat = urcrnrlat; map.urcrnrlon = urcrnrlon
map.llcrnry = map.llcrnrlat; map.llcrnrx=map.llcrnrlon
map.urcrnry = map.urcrnrlat; map.urcrnrx=map.urcrnrlon
map.aspect = (map.urcrnrlat-map.llcrnrlat)/(map.urcrnrlon-map.llcrnrlon)
return map

This only works for projection='cyl'. For other projections more work is 
needed (see basemap.py).

- Jesper

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Basemap reuse

2007-06-01 Thread Jesper Larsen
Hi matplotlib users,

I have a small web application for calculating tsunami travel times 
(http://ocean.dmi.dk/apps/tsunami). The application uses matplotlib/basemap 
for producing contour maps of the tsunami travel times.

To speed up the response time of the application I made a version in which the 
calculations are performed for every second integer longitude and latitude 
for calculation windows of 60x60 degrees lon x lat, 90x90, 180x180 and 
global. This is a lot of plots for which I am making a new Basemap instances 
for each plot since:

llcrnrlon
llcrnrlat
urcrnrlon
urcrnrlat

differs for each plot. The initialization of the Basemap instances are 
responsible for the vast majority of the CPU usage in the application.

In converting the application to numpy (from numarray) I was wondering whether 
I could reduce the plotting time as well. Is it possible to reuse a Basemap 
instance somehow in my case or is that out of the question?

Regards,
Jesper

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] noob questions

2007-05-24 Thread Jesper Larsen
Hi Trevis,

On Wednesday 23 May 2007 17:17, Trevis Crane wrote:
 1)  It's pretty easy to include text on a graph, but are LaTex strings
 supported?  That is, I want to write something like this on my plot:
 '\Phi_0 = blah...'.  When passing a LaTex command as part of text string
 to be written on a plot in MatLab, it interprets this and displays the
 (in this case) Greek symbol.  Any suggestions on how this is or should
 be done with matplotlib?

See the chapter on mathtext on page 32 in the user guide:

http://matplotlib.sourceforge.net/users_guide_0.90.0.pdf

 2) How do I format how tick mark labels are displayed?  I have a plot
 whose x-axis runs from 0 to 8.5e-5.  But the tick mark labels are
 0,0.1,0.2,0.3...  This is rather unsightly, but I haven't
 found a way to specify the format of these numbers.

That is described on page 52 in the user guide (see listing 6.1 for an 
example).

Hope this helps.

Cheers,
Jesper

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Reusing basemap instance

2007-05-11 Thread Jesper Larsen
On Thursday 10 May 2007 17:12, Simon Kammerer wrote:
 I use a list for every category of items (contoursets, clabels, texts,
 ...), as the way to remove them is slightly different.

 Then I remove them from the map axes:

 for contourset in contoursets_to_remove:
   for coll in contourset.collections:
 if coll in map_axes.collections:
   map_axes.collections.remove(coll)


 for label in clabels_to_remove:
   if label in map_axes.artists:
map_axes.artists.remove(label)


 for txt in texts_to_remove:
   if txt in map_axes.texts:
map_axes.texts.remove(txt)

Thanks, that reduced the plotting time by an additional factor two (besides 
what I got from reusing the basemap instance). The remaining stuff seems hard 
to do anything about:

- filling masked arrays in matplotlib ~15% of the CPU time
- writing the png file (write_png) ~15%
- drawing (non-reusable) polygon collections (draw_poly_collection) ~15%
- drawing line collections (draw_line_collection) ~7%
...

Cheers,
Jesper

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Reusing basemap instance

2007-05-08 Thread Jesper Larsen
On Monday 07 May 2007 16:46, Jeff Whitaker wrote:
 Jesper:  Can you be more specific about why you need a deepcopy?  Those
 methods you mention do not modify the Basemap instance, although they do
 modify the axes instance they are used with.  It shouldn't be a problem
 reusing the Basemap instance with a new axes instance (without using
 using deepcopy).

Thanks Jeff,

You are absolutely right, I have changed my code so that it does not perform a 
deepcopy now. I must have done something wrong when I wrote the code some 
time ago (I think, maybe I was confused by the memory issues we discussed a 
while ago).

I am considering reusing an entire figure instance (which I guess I will have 
to copy) as well instead of just the basemap instance but I don't know if it 
is worth the effort or it is just as fast to redo the figure based on the 
basemap instance. I consider doing it because the map decorations are 
unchanged between the plots - a profiling of the application reveals that 
they take a considerable amount of time to perform. Any recommendations on 
that issue?

- Jesper

Ps. You can see a test/development version of the web application for which I 
am using matplotlib/basemap in (besides for my scientific work) here (if it 
is running when you read this):

http://ocean.dmi.dk/apps/forecast/

(some bugs remain)

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Reusing basemap instance

2007-05-07 Thread Jesper Larsen
Hi matplotlib basemap users,

I am doing a lot of plots of the same area but for different vertical levels, 
time steps and parameters. I am therefore trying to reuse my basemap instance 
(which in some cases is quite time consuming to setup). I am doing this by 
making a deepcopy of a basemap instance created by this simple function 
(where mapresolution is a function giving the different map resolutions for 
different areas):

def getbasemap(area):
  Returns basemap instance for a given area.
  from matplotlib.toolkits import basemap
  mapres = mapresolution(area)
  m = basemap.Basemap(area[0], area[1], area[2], area[3], resolution=mapres)
  return m

The deepcopy operation takes almost as much time as creating a new basemap 
instance. If the basemap instance was unchanged by my plotting I would of 
course be able to avoid doing this and simply use a basemap instance without 
copying it. Am I right in asserting that this is not the case? Any 
suggestions on how to avoid deepcopying it?

Cheers,
Jesper


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Reusing basemap instance

2007-05-07 Thread Jesper Larsen
On Monday 07 May 2007 16:02, Jesper Larsen wrote:
 The deepcopy operation takes almost as much time as creating a new basemap
 instance. If the basemap instance was unchanged by my plotting I would of
 course be able to avoid doing this and simply use a basemap instance
 without copying it. Am I right in asserting that this is not the case? Any
 suggestions on how to avoid deepcopying it?

I forgot to mention that the reason I have to deepcopy it is that I cannot use 
the basemap methods:

drawparallels()
drawmeridians()
fillcontinents()
drawcoastlines()

without an axes instance which is again tied to a figure instance. These 
methods seem to modify the basemap instance (as far as I recall).

- Jesper

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread Jesper Larsen
Hi matplotlib users,

I'm using matplotlib for a long running process. Unfortunately the memory 
usage continue to grow as the process runs. I have appended a simple example 
which illustrates this at the end of this mail. Unfortunately I haven't 
figured out how to use the information obtainable from gc for anything useful 
in this regards.

Kind regards,
Jesper


My system is:

 uname -a
Linux sea 2.6.15-28-686 #1 SMP PREEMPT Thu Feb 1 16:14:07 UTC 2007 i686 
GNU/Linux

 python
Python 2.4.4 (#1, Nov 16 2006, 13:39:46)
[GCC 3.3.3 (Debian)] on linux2
Type help, copyright, credits or license for more information.
 import matplotlib
 print matplotlib.__version__
0.87.6
 from matplotlib.toolkits import basemap
 print basemap.__version__
0.9.4

Test code:

import os, gc
import PyNGL.Nio as Nio
from matplotlib.toolkits import basemap
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
import pylab

def report_memory(i):
  pid = os.getpid()
  a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
  print i, ' ', a2[1],
  return int(a2[1].split()[1])

def plot():
  #gc.set_debug(gc.DEBUG_LEAK)
  lon = pylab.linspace(-4.08300018311, 30.25, 207)
  lat = pylab.linspace(48.542371, 65.8499984741, 174)
  xo, yo = pylab.meshgrid(lon, lat)
  bmap = basemap.Basemap(-4, 48, 30, 66)
  xlon, ylat = bmap(xo,yo)

  fig = pylab.Figure()
  canvas = FigureCanvas(fig)

  i = 0
  while True:
report_memory(i)

fig.clear()
cs = bmap.contourf(xlon, ylat, xo)
del cs

i += 1

if __name__ == '__main__': plot()

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users