[Matplotlib-users] MEP 12: Gallery cleanup example

2013-09-29 Thread Tony Yu
Since the 1.3 release, the Matplotlib gallery has displayed the beginnings
of a clean up effort that will probably require the work of many people. To
make it easier to contribute to the effort, there's already a MEP
(Matplotlib Enhancement Proposal) that details some guidelines for clean up:

https://github.com/matplotlib/matplotlib/wiki/MEP12

To make some of these goals clearer, I just submitted a PR which could
serve as an example of those guidelines in action:

https://github.com/matplotlib/matplotlib/pull/2474

Anyone who is interested in helping out with the clean-up should take a
look at those links and then find an example that needs cleaning up.

Cheers,
-Tony
--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] streamplots in axesgrid

2013-10-06 Thread Tony Yu
On Thu, Sep 26, 2013 at 10:37 AM, Yoshi Rokuko  wrote:

> Hey,
>
> I'm trying to plot streamplots into an axesgrid object with something
> like:
>
> fig = pl.figure(1, (13, 20))
> grid = AxesGrid(fig, 111,
> nrows_ncols = (3, 2),
> axes_pad = 0.6,
> cbar_location = 'top',
> cbar_mode = 'each',
> cbar_size = '2%',
> cbar_pad = '1%',
>)
> [...]
> norm = mpl.colors.LogNorm(vmin=1, vmax=5000)
> im = grid[i].streamplot(XPTS, YPTS, zx, zy,
> color=zr,
> arrowsize=.001,
> norm=norm)
> grid.cbar_axes[i].colorbar(im)
> [...]
>
> and then it failes with:
>
> Traceback (most recent call last):
>   File "./results.py", line 96, in 
> grid.cbar_axes[i].colorbar(im)
>   File
> "/usr/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/axes_grid.py",
> line 85, in colorbar cb = Colorbar(self, mappable,
> orientation=orientation, **kwargs) File
> "/usr/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/colorbar.py",
> line 706, in __init__ mappable.autoscale_None() # Ensure
> mappable.norm.vmin, vmax AttributeError: 'StreamplotSet' object has no
> attribute 'autoscale_None'
>
> can't I use streamplots in axesgrid? If I comment out the colorbar for
> the streamplot colors it works ...
> Is this a bug? Is there a right way to do it? Is there a work around?
>

Hi Yoshi,

The return value for streamplot is a bit hacked together. Its just a simple
object containing a line collection and an arrow collection. Instead of
passing the set of collections, just pass one of the collections to the
colorbar. For example:

sset = grid[i].streamplot(XPTS, YPTS, zx, zy, color=zr)
grid.cbar_axes[i].colorbar(sset.lines)

Does that work for you?

Best,
-Tony


>
> Many thanks in advance!
>
> Regards, Yoshi
--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Matplotlib style gallery

2015-01-05 Thread Tony Yu
I've been playing around with learning Javascript lately. As part of the
process, I created a Flask app to build a gallery for matplotlib style
sheets:

https://github.com/tonysyu/matplotlib-style-gallery

If you run that locally, you can actually input styles, either with a URL
to a *.mplstyle file or with matplotlibrc commands. Here's a static version
without the custom inputs:

http://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html

Ideally, I'd get this into a form that could be submitted as a PR for the
matplotlib website, but I'll need a bit more spare time to learn some more
web development (sessions, client storage, etc).

Cheers!
-Tony
--
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [matplotlib-devel] Matplotlib style gallery

2015-01-08 Thread Tony Yu
Thanks Max!

I was planning to add a more interactive interface, really similar to what
you're suggesting. I haven't gotten around to it, but hopefully, I'll have
some time to play around with that.

On Thu, Jan 8, 2015 at 4:56 PM, Maximilian Albert <
[email protected]> wrote:

> Hi Tony,
>
> This is awesome. Great work!
>
> I was wondering, is there an easy way to cycle through all available
> styles for a given plot? For instance, clicking on the top left plot
> displays a maximized image of the "bmh" style. It would be great if one
> could press arrow-down (say)  to cycle through the other styles
> "dark_background", "fivethirtyeight", etc. for a quick comparison.
>
> Cheers,
> Max
>
>
> 2015-01-06 4:42 GMT+00:00 Tony Yu :
>
>> I've been playing around with learning Javascript lately. As part of the
>> process, I created a Flask app to build a gallery for matplotlib style
>> sheets:
>>
>> https://github.com/tonysyu/matplotlib-style-gallery
>>
>> If you run that locally, you can actually input styles, either with a URL
>> to a *.mplstyle file or with matplotlibrc commands. Here's a static version
>> without the custom inputs:
>>
>> http://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html
>>
>> Ideally, I'd get this into a form that could be submitted as a PR for the
>> matplotlib website, but I'll need a bit more spare time to learn some more
>> web development (sessions, client storage, etc).
>>
>> Cheers!
>> -Tony
>>
>>
>> --
>> Dive into the World of Parallel Programming! The Go Parallel Website,
>> sponsored by Intel and developed in partnership with Slashdot Media, is
>> your
>> hub for all things parallel software development, from weekly thought
>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>> look and join the conversation now. http://goparallel.sourceforge.net
>> ___
>> Matplotlib-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>>
>>
>
--
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Plotting style

2015-03-03 Thread Tony Yu
On Tue, Mar 3, 2015 at 11:50 AM, Gökhan Sever  wrote:

> I see seaborn has "paper, notebook, talk, and poster" options.
> http://stanford.edu/~mwaskom/software/seaborn-dev/aesthetics.html
> Apperantly he scales each parameter to get modified views. This would be a
> good addition for any of the styles available in matplotlib.
>

A similar pattern with `matplotlib.style` would use chained stylesheets.
The idea would be to make stylesheets either aesthetics focused or layout
focused. By aesthetics, I mean things like colors and marker shape, and by
layout, I mean things like default figure size, figure padding, font size,
etc. Then you can easily have a style that defines the general aesthetics
and easily modify it for papers, talks, etc.

Here's an example from `mpltools`, but the same syntax applies to the
`style` module in `matplotlib`:

http://tonysyu.github.io/mpltools/auto_examples/style/plot_multiple_styles.html

(PoF = Physics of Fluids journal; IIRC I think I have some personal
stylesheets that take the normal two-column figure layout and convert it to
a full-page layout.)

-Tony


>
> On Tue, Mar 3, 2015 at 12:35 PM, Marin GILLES  wrote:
>
>>  Le 03/03/2015 18:15, Gökhan Sever a écrit :
>>
>>
>>
>> On Tue, Mar 3, 2015 at 12:07 PM, Marin GILLES 
>> wrote:
>>
>>>
>>>   Sure, I'll be careful about that.
>>> I'm going to go try and design some new interesting ones.
>>> Maybe adding some styles specific to some plot types could be useful.
>>> Also some styles specific for some applications (geoscience, biology)?
>>> If you have any other ideas, please let me know.
>>>
>>> --
>>> *Marin GILLES*
>>>
>>
>>  It would be good to have styles for "paper" and "presentation" modes.
>> The former would have smaller ticks, labels, linewidths, other axis
>> elements that goes into a journal publication, while the latter with much
>> magnified elements to be clearly visible on a screen from the back of a
>> room.
>>
>> Indeed it would be a very good idea.
>> I've seen that already in the seaborn lib I guess.
>>
>> --
>> *Marin GILLES*
>>
>> *PhD student CNRS *
>>
>>
>>
>> * Laboratoire Interdisciplinaire Carnot de Bourgogne (ICB) UMR 6303 CNRS
>> - Université de Bourgogne 9 av Alain Savary, BP 47870 21078, Dijon (France)
>> * ☎ (+33)6.79.35.30.11
>> ✉ [email protected]
>>
>
>
>
> --
> Gökhan
>
>
> --
> Dive into the World of Parallel Programming The Go Parallel Website,
> sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for
> all
> things parallel software development, from weekly thought leadership blogs
> to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Plotting style

2015-03-03 Thread Tony Yu
On Tue, Mar 3, 2015 at 1:37 PM, Marin GILLES  wrote:

>  Le 03/03/2015 18:53, Thomas Caswell a écrit :
>
> I was thinking of the stand alone repository to just  store the style
> files as the style module handles the loading pretty well.
>
> The main motivation for this would be to decouple the release cycle of the
> styles (which can be very fast) from the library (which needs to be slower).
>
> 


> Maybe a dumb question, but I'm quite new to this...
> Can this be integrated in mpl afterwards? Or does it needs to be a
> standalone package that you install on its own?
> If it can be integrated, how?
> Thanks
> Marin Gilles
>

Any stylesheet could easily be integrated afterwards, but the separate repo
would allow faster releases, as Thomas suggests above, and also more
experimentation. It would probably make sense to integrate just the cream
of the crop from the style repo into Matplotlib-proper, but it'd still be
easy to use the less popular ones. For example, you wouldn't even have to
install the style repo---you can pass a url to `matplotlib.style.use`.

The separate repo could also incorporate a default comparison page to
quickly decide on the most appropriate stylesheet; e.g.:

https://github.com/tonysyu/matplotlib-style-gallery

-Tony
--
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib basemap streamlines plot

2015-03-30 Thread Tony Yu
On Mon, Mar 30, 2015 at 2:15 PM, Foehn  wrote:

> Am 2015-03-27 um 15:01 schrieb Sappy85:
> > Hi all,
> >
> > tried to plot a streamline with matplotlib. So far it work's.
> > But my question: Is there a possibility to avoid the gaps in the
> streamlines
> > (see my picture)?
>

I think the problem is that the streamline algorithm doesn't make any
attempt to optimize for longer streamlines. It's been a long time since
I've looked at the code, but roughly speaking, the algorithm optimizes for
spacing between streamlines. Reducing the `minlength` input *should*
slightly prefer longer streamlines, but you'll see side-effects with lines
near borders and diverging flows.

If changing the `streamplot` implementation is an option, one of the
simpler ways to achieve streamlines with fewer gaps would be allow the grid
of starting points to vary independently from the grid that determines that
streamlines are "too close". There are also "smarter" ways of seeding the
streamlines, but that would be a bit more work, I believe.

-Tony


> >
> > 
>
> Are you sure your flow is non divergent? Otherwise sinks and sources of
> streamlines are quite natural. If your flow is divergence free I I
> frankly admit that I have no idea how to solve the problem with the
> (then) spurious gaps.
>
> Regards, Foehn
>
>
> >
> > Regards
> > Sappy85
> >
> > --
> > View this message in context:
> http://matplotlib.1069221.n5.nabble.com/matplotlib-basemap-streamlines-plot-tp45276.html
>
>
--
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [matplotlib-devel] Matplotlib style gallery

2016-03-28 Thread Tony Yu
Well... this is a *really* late reply, but I finally got around to adding
easier navigation for the style gallery
<https://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html>.
I
also added an update for styles added in Matplotlib 1.5 and wrote a quick
post <https://tonysyu.github.io/matplotlib-style-gallery.html#.VvoAzxIrKV4>.

Cheers!
-Tony

On Thu, Jan 8, 2015 at 8:10 PM, Tony Yu  wrote:

> Thanks Max!
>
> I was planning to add a more interactive interface, really similar to what
> you're suggesting. I haven't gotten around to it, but hopefully, I'll have
> some time to play around with that.
>
> On Thu, Jan 8, 2015 at 4:56 PM, Maximilian Albert <
> [email protected]> wrote:
>
>> Hi Tony,
>>
>> This is awesome. Great work!
>>
>> I was wondering, is there an easy way to cycle through all available
>> styles for a given plot? For instance, clicking on the top left plot
>> displays a maximized image of the "bmh" style. It would be great if one
>> could press arrow-down (say)  to cycle through the other styles
>> "dark_background", "fivethirtyeight", etc. for a quick comparison.
>>
>> Cheers,
>> Max
>>
>>
>> 2015-01-06 4:42 GMT+00:00 Tony Yu :
>>
>>> I've been playing around with learning Javascript lately. As part of the
>>> process, I created a Flask app to build a gallery for matplotlib style
>>> sheets:
>>>
>>> https://github.com/tonysyu/matplotlib-style-gallery
>>>
>>> If you run that locally, you can actually input styles, either with a
>>> URL to a *.mplstyle file or with matplotlibrc commands. Here's a static
>>> version without the custom inputs:
>>>
>>>
>>> http://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html
>>>
>>> Ideally, I'd get this into a form that could be submitted as a PR for
>>> the matplotlib website, but I'll need a bit more spare time to learn some
>>> more web development (sessions, client storage, etc).
>>>
>>> Cheers!
>>> -Tony
>>>
>>>
>>> --
>>> Dive into the World of Parallel Programming! The Go Parallel Website,
>>> sponsored by Intel and developed in partnership with Slashdot Media, is
>>> your
>>> hub for all things parallel software development, from weekly thought
>>> leadership blogs to news, videos, case studies, tutorials and more. Take
>>> a
>>> look and join the conversation now. http://goparallel.sourceforge.net
>>> ___
>>> Matplotlib-devel mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>>>
>>>
>>
>
--
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] axis labels clipped

2011-09-23 Thread Tony Yu
On Fri, Sep 23, 2011 at 9:01 AM, Kurt Mueller  wrote:

>
> Without the resize event it works as expected.
> With the resize event (as you suggested),
> it only adjusts the borders of the four axes to the outside of the figure.
> But between the axes there is no space at all.
>
> Do I miss something?
>

I think I was saying (I'm not certain, since it's been a while since the
original email) that the function (layout.tight) had to be called again
*after* resizing.

BTW, one of the matplotlib devs (Jae Joon Lee, I believe) completely
rewrote/improved this function and added it to matplotlib as
tight_layout(both
as a pyplot function and a figure method). I'm not sure if the
function is in the current mpl release, but there's a pending release in the
works.

Best,
-Tony
--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] scatter plot without edge color

2011-10-15 Thread Tony Yu
On Sat, Oct 15, 2011 at 8:55 AM, Chao YUE  wrote:

> Dear all,
>
> how can I make a scatter plot without edgecolor?
>
> import matplotlib.pyplot as plt
> In [110]: plt.scatter(np.arange(10),np.arange(10,20),edgecolor=None)
> Out[110]: 
>
> in this case I can use edgecolor='w' to solve it, but when points overlap,
> this does not work anymore.
> Any help will be appreciated. Thanks.
>

Hi Chao,

I think what you want is 'none':

plt.scatter(np.arange(10),np.arange(10,20), color='y',edgecolor='none')

It's confusing, but None is used to let matplotlib auto-select the color,
while 'none' is used to turn off edge coloring.

Best,
-Tony
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 1 colorbar on 2 subplots.

2011-11-04 Thread Tony Yu
On Fri, Nov 4, 2011 at 4:49 PM, Rahul Mahajan  wrote:

> Hi,
> I am trying to put 1 colorbar on 2 subplots, but failing miserably.
>
> I have tried multiple approaches, involving subplot2grid, add_axes,
> AxesGrid etc.
>
> If anyone has a "canned" routine or knows what to do, your help is greatly
> appreciated.
>
> Here is my code block:
>
>   fig = pyplot.figure()
>
> ax1 = pyplot.subplot2grid((2,2),(0,0))
> cx1  = pyplot.contourf(x,y,var1,var_cint,origin='lower',extend='both')
>
> ax2 = pyplot.subplot2grid((2,2),(0,1))
> cx2  = pyplot.contourf(x,y,var2,var_cint,origin='lower',extend='both')
>
> Now I want to put 1 colorbar to these subplots.
>

This example seems to be a very simple example of what you want:
http://matplotlib.sourceforge.net/examples/pylab_examples/subplots_adjust.html

Basically, you need to create an axes specifically for the colorbar (e.g.
`colorbar_ax`) and call pyplot.colorbar(cax=colorbar_ax); or you can let
mpl automatically take space from one of your existing axes: for example,
pyplot.colorbar(ax=ax2).

You can also pass a mappable to pyplot.colorbar (in your example, cx1 or
cx2), but by default, it will grab the most recently created one. Note,
using the single colorbar for both subplots *only* makes sense if var_cint
(in your code) is defining the *values* of the contour levels (as opposed
to the *number* of contour levels). Otherwise, the colorbar will only be
accurate for one of the two plots.

HTH,
-Tony
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plots points corresponding to a list of values - similar to listplot of mathematica

2011-11-06 Thread Tony Yu
On Sun, Nov 6, 2011 at 8:20 AM, Gousios George wrote:

> Hello,
> Is there a way?Like the title says?
> I have a 2d list  :
> > [[ 0  1]
> >  [ 1  1]
> >  [ 1  0]
> >  [ 2  0]
> >  [ 1  0]
> >  [ 2  0]
> >  [ 1  0]
> >  [ 0  0]
> >  [ 1  0]
> >  [ 1 -1]]
>
> and  i want to do the "listplot' from mathematica.
>

I don't know of a plot function to do this, but one extra line of code
should suffice:

pts = [[0, 1],
[1, 1],
[1, 0],
[2, 0],
[1, 0],
[2, 0],
[1, 0],
[0, 0],
[1, 0],
[1,-1]]
x, y = np.transpose(pts)
plt.plot(x, y)


Best,
-Tony
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Matplotlib colors

2011-11-16 Thread Tony Yu
On Wed, Nov 16, 2011 at 5:35 PM, Jonno  wrote:

> I want to:
> 1. Have matplotlib assign the linecolor for a plot
> 2. Read the linecolor with .get_color()
> 3. Create another plot with the linecolor set to a lighter version of
> the previous linecolor.
>
> Ie:
>
> a, = plot(x,y)
> a.get_color() = 'b'
> b, = plot(x,y, color = "#xx")
>
> Since I'm only using the standard matplotlib assigned colors which
> cycle through b,g,r,c,m,y,k I thought I would just create a mapping
> between each color and a lighter version.
>
> How do I get the hex or RGB string for the base matplotlib colors?
>

There may be an easier way, but in the past I've used a color converter
object
(which seems unnecessarily verbose):

>>> import matplotlib.colors as mcolors
>>> cc = mcolors.ColorConverter()
>>> cc.to_rgb('b')
(0, 0, 1)



>
> Also, if there's a different property I can use to lighten the line
> color without changing the color that would be cool too.
>

If you have a white background (and no overlapping markers/lines), you
could just set the "alpha" argument in the plot command.

Best,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Plot trajectories with arrow tips

2011-11-17 Thread Tony Yu
On Sun, Nov 13, 2011 at 7:52 AM, asd dasdas  wrote:

> Hi everyone,
>
> can someone please help me how to make a plot like this:
> http://tutorial.math.lamar.edu/Classes/DE/PhasePlane_files/image002.gif
>
> The main issue with it is in the (black) trajectories. As far as i know
> there is no function in matplotlib to plot trajectories with arrows
> pointing in a direction.
>
> But I think a good workaround is: plotting the trajectories with plot(..)
> and use quiver(..) at certain points to get an arrows.
>
> A minimal example would be:
>
> import matplotlib.pyplot as plt
> import numpy as np
> import scipy.integrate as integrate
>
> if __name__=="__main__":
> t = np.linspace(0, 20, 1000)
> l = 3
> # some starting points
> X0s = [[-3.0, 0],
> [-3.0, -1],
> [-3.0, -2],
> [-2, -3.0],
> [-1, -3.0],
> [0, -3.0],
> [1, -3.0],
> [2, -3.0],
> [3.0, -2],
> [3.0, -1],
> [3.0, 0.0],
> [3.0, 1],
> [3.0, 2],
> [2, 3.0],
> [1, 3.0],
> [0, 3.0],
> [-1, 3.0],
> [-2, 3.0],
> [-3.0, 2],
> [-3.0, 1],
> [0, 0.01],
> [0, -0.01],
> [0.01, 0],
> [-0.01, 0]]
> sattel = lambda x,t=0: [-x[0], x[1]]
> plt.axis([-l,l,-l,l])
>
> for X0 in X0s:
> state = integrate.odeint(sattel, X0, t).T
> plt.plot(*state, color="k", linewidth=1)
> xs = state[:,::10]
> x_ds = np.asarray(sattel(xs))
> M = np.hypot(x_ds[0],x_ds[1])
> plt.quiver(xs[0],xs[1],x_ds[0]/M,x_ds[1]/M,
> pivot="mid")#,scale=100, scale_units="width",linewidth=5)
>
> plt.axis([-l,l,-l,l])
> plt.show()
>
> That is pretty much what I was looking for except the shafts of the arrows
> that I can't get rid off.
> You can see what I tried to get this done by uncomment the quiver
> parameter.
> Doing this, you can see, the shafts are (nearly) gone, but the arrows look
> horrible. I wonder if there is anyway to tell quiver(..) to only plot the
> heads of the arrow, without the shaft.
>
> Can you please give me a hint how to do this?
>
>
You can increase both the "headlength" and "headaxislength" parameters.
It's admittedly pretty hacky, but I think it'll do what you want.

Also, this is related to a previous discussion on streamlines. A couple of
users were kind enough to post code in this
thread.
(And there was talk of integrating one or both of these into matplotlib.)
I've actually been using a modified version of Tom Flannaghan's code. Tom's
code  uses a
FancyArrowPatch to draw the arrow heads, which may be an alternative
approach to using quiver. Note that neither streamline function allows you
to specify starting points (you specify the streamline density and the
algorithms pick their own starting points).

Best,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Removing ticks and frame (imshow)

2011-11-28 Thread Tony Yu
On Thu, Nov 24, 2011 at 9:48 AM, Marianne C.  wrote:

> Hi all,
>
> My name is Marianne, I am a beginner user of matplotlib.
> I am using imshow in pyplot.  I am desperate to get rid of
> the ticks on both x and y axes (see attached picture).  I
> do not need the black box around the data either.  Should
> I use imshow in axes.Axes instead, to be able to call
>
> set_ticks_position("none")?
>
> Thank you for your help,
> Marianne
>
> Here is the code so far:
>
> import numpy
> from matplotlib import pyplot
>
> q=numpy.loadtxt('field.txt')
>
> myfield = pyplot.imshow(q,aspect=1)
> myfield.set_clim(vmin=0, vmax=0.6)
>
> pyplot.colorbar()
>
> pyplot.savefig('field_1.eps')
>


There are a number of ways to accomplish this, but the one I use is to make
the x and y axes invisible (gets rid of the ticks) and also make the spines
invisible (gets rid of the lines). I just throw these changes into a
utility function (`clear_frame` below) and put that in a module that's on
my python path so that it's easily reusable.

Hope that helps,
-Tony

#~~~
import numpy as np
import matplotlib.pyplot as plt

def clear_frame(ax=None):
if ax is None:
ax = plt.gca()
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
for spine in ax.spines.itervalues():
spine.set_visible(False)

img = np.random.random((100,100))
plt.imshow(img)
clear_frame()

plt.colorbar()

plt.show()
#~~~
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] pie colors

2011-11-30 Thread Tony Yu
On Wed, Nov 30, 2011 at 10:34 AM, Grigoris Maravelias <
[email protected]> wrote:

> Hello list!
>
> I have a question regarding the colors of the pie diagram of matplotlib.
> When no colors are assigned then the pie function automatically selects
> some colors, like the example image I have attached. But in this case the
> black color covers the text. How can we avoid this?Is there an easy
> (perhaps?) way to exclude a color?
>

I don't really use pie charts, but I think it just uses the default color
cycle. This can be altered by changing the rcParams:

>>> import matplotlib.pyplot as plt
>>> plt.rcParams['axes.color_cycle'].remove('k')

The color_cycle parameter is just a python list, so I use list.remove to
remove black (which is the letter 'k' since 'b' is blue). There are other
ways of setting rcParams, as detailed in the help
files(Note
that `rc` and `rcParams` is in both matplotlib.pyplot and the main
matplotlib package).

Best,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Normalized Histograms

2011-11-30 Thread Tony Yu
On Wed, Nov 30, 2011 at 11:42 AM, Jeffrey Blackburne <
[email protected]> wrote:

> Hi Steven,
>
> Try this:
>
> import numpy as np
> import numpy.random
> import matplotlib as mpl
> import matplotlib.pyplot as plt
>
> x = np.random.randn(1000)
> h, binedg = np.histogram(x, 10)
>
> wid = binedg[1:] - binedg[:-1]
> plt.bar(binedg[:-1], h/float(x.size), width=wid)
>
>
> On Nov 30, 2011, at 10:25 AM, Steven Boada wrote:
>
> > Hi Users,
> >
> > I'm looking to make a histogram that is normalized by the total number
> > of items shown in the histogram. For example:
> >
> > Let's say that I have an array 1000 items long. If I make a
> > histogram in
> > the normal way hist(x,10) then I get a histogram showing the total
> > number of items in each bin. What I want to do is take that total
> > number
> > in each bin and divide them by 1000 and then make the plot.
> >
> > So if one of my bins has 350 objects in it, then it would be
> > changed to
> > 0.35.
> >
> > Another way to say it would be that I want the height of the histogram
> > to represent the fraction of the total. I am pretty sure that this is
> > different than using the "normed=True" flag, but I couldn't find
> > anyone
> > talking about this when I searched.
> >
> > Thanks
> >
> > Steven
>
>
One option: You can plot the normal `hist` and then change the tick labels
appropriately. Here's some code for accomplishing that:

#~~~
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, MultipleLocator


N = 350
ytick_step = 0.05
data = np.random.normal(size=N)

def norm_num(x, pos):
return '%g' % (x / float(N))

locator = MultipleLocator(N * ytick_step)
formatter = FuncFormatter(norm_num)

f, ax = plt.subplots()
ax.yaxis.set_major_formatter(formatter)
ax.yaxis.set_major_locator(locator)
ax.hist(data)

plt.show()
#~~~

Note that the formatter object is all you need to change to the desired
scale. But, that result will usually look ugly, because you'll get tick
labels with long, ugly floating point numbers. The locator object fixes
that issue.

Best,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] pie colors

2011-11-30 Thread Tony Yu
On Wed, Nov 30, 2011 at 6:31 PM, Grigoris Maravelias <
[email protected]> wrote:

> **
> Well I did tried this but it didn't work out. It actually removes the
> black color from the color_cycle but the pie still prints it. Moreover I
> noticed that this color_cycle has 7 colors that repeats after the first 7
> so it won't do what I want. I will need to find another way to set the
> colors or just avoid the pie.
>
>
I guess I should atleast read the docstring for plt.pie before giving you
advice on how to use it. It looks like the default colors are hard coded
into the function (instead of using the color_cycle parameter).

The quickest way to create different colors is to pick them out from a
colormap. For example, the following gives decent results:

>>> colors = plt.cm.Set1(np.linspace(0,1,9))
>>> plt.pie(np.ones(9), colors=colors)

Of course, trying to get more (visually-differentiable) colors out of the
color map will be difficult.

Hope that helps,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how to use different font for serif

2011-12-02 Thread Tony Yu
On Fri, Dec 2, 2011 at 4:13 PM, Jonathan Slavin wrote:

> Hi all,
>
> I've been trying to use a different serif font for a plot and have been
> running into problems.  I thought I could just do something like:
>
> from matplotlib import rc
> rc('font', family='serif', serif='Times New Roman')
>
> but if I try that I end up getting:
> findfont: Font family ['serif'] not found. Falling back to Bitstream
> Vera Sans
>
> It works fine without the serif='...' part and gives me the default
> serif font.  I know that Times New Roman exists on my system -- at least
> the GNOME character map can find it.  Perhaps I need to use a different
> alias (but what would it be?).  Any help would appreciated.
>
> Jon
>


You should check what fonts are installed on your system:

>>> from matplotlib import font_manager
>>> font_manager.OSXInstalledFonts()

(or if you're on a different system, try MSInstalledFonts or
X11InstalledFonts---those aren't available on my system, but presumably
that's just because I'm using OSX). If that works, then look for Times New
Roman in what's printed out. If it is, the problem may be that it's not the
right format: it appears as
ifthe
font_manager only supports .ttf and .afm fonts.

If you don't see Times New Roman in any of those files, check the output of

>>> mpl.font_manager.OSXFontDirectories

(replacing OSX with MS or X11, if needed). If the listed directories
doesn't match your installation of Times New Roman, that's your problem.
(I'm not sure if there's a good way of adding directories.)

Cheers,
-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Using plt.pcolormesh with FuncAnimation

2011-12-04 Thread Tony Yu
On Sun, Dec 4, 2011 at 9:59 AM, Manuel Jung
wrote:

> Hi,
>
> I have plt.pcolormesh plot i would like to animate. So i've taken a
> look at the various examples and decided to go with the FuncAnimation
> routine. This works for me, but im using for every frame a new call to
> plt.colormesh and i am not updating the underlaying data, like in this
> example
> http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html
> This is because there seems to be no set_data, set_array or similar
> for the from plt.colormesh returned object (an instance of
> matplotlib.collection.QuadMesh). Am i right? Is there any way i can
> update the data structures of plt.colormesh?
>
> Hi Manuel,

You can call QuadMesh's `set_array` method, just as you can for images.
(You suggest there is no set_array method for QuadMesh; are you sure about
that?) The strange part is that it expects a 1d array, where as colormesh
accepts arrays of various dimensions.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> mesh = plt.pcolormesh(np.random.rand(10,10))
>>> mesh.set_array(np.random.rand(10,10).ravel())
>>> plt.draw()

set_array doesn't complain if you remove the call to `ravel`, but
`plt.draw()` will complain.

-Tony
--
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Round pie in non square figure size

2011-12-07 Thread Tony Yu
On Wed, Dec 7, 2011 at 11:08 AM, claudius  wrote:

>
> I would like to draw a round pie in a rectangle figure. At the moment I'm
> using something like:
>
>fig = plt.figure( figsize = figsize, dpi=inch)
>
># plot actually
>ax = fig.add_subplot( 1, 1, 1 )
>ax.pie( value_list, labels = labels_list, **kwargs )
>
>plt.savefig( plt_pathname )
>plt.close()
>
> If the figsize is not square ( eg. [4, 4]) then the resulting figure will
> be
> stretched, elipsoid.
> Can I overcome this issue.
> Thanks in advance
>
> You can set the aspect of the axes object:

ax.set_aspect('equal')

Best,
-Tony
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] need help with Times New Roman font.

2011-12-07 Thread Tony Yu
On Wed, Dec 7, 2011 at 8:27 PM, Piter_  wrote:

> Hi all.
> I want to use "Times New Roman" font for my pictures.
> Searching the list I have found this solution:
> __
> 
> pylab.rc('font', family='serif')
> pylab.rc('font', serif='Times New Roman')
> pylab.rc('text', usetex='false')
> ..
> 
>
> yl=pylab.ylabel(r'Difference extinction coeffitient, ($M  \times
> cm^{-1})$',fontsize=8)
> xl=pylab.xlabel("Wavelength, (nm)", fontsize=8)
>
> However it still does not use Times new roman.
>
> >>> yl.get_fontname()
> 'DejaVu Serif'
> >>> xl.get_fontname()
> 'DejaVu Serif'
> >>>
>
> I have the font:
>
> >>> font_manager.findfont('Times New Roman')
> '/usr/share/fonts/truetype/msttcorefonts/Times_New_Roman.ttf'
>
> and here are rcparams
>
> >>font_manager.rcParams
> {'figure.subplot.right': 0.90002, 'mathtext.cal':
> 'cursive', 'font.fantasy': ['Comic Sans MS', 'Chicago', 'Charcoal',
> 'ImpactWestern', 'fantasy'], 'xtick.minor.pad': 4, 'tk.pythoninspect':
> False, 'image.aspect': 'equal', 'font.cursive': ['Apple Chancery',
> 'Textile', 'Zapf Chancery', 'Sand', 'cursive'],
> 'figure.subplot.hspace': 0.20001, 'xtick.direction': 'in',
> 'axes.facecolor': 'w', 'mathtext.fontset': 'cm', 'ytick.direction':
> 'in', 'svg.image_inline': True, 'lines.markersize': 6, 'figure.dpi':
> 100.0, 'text.usetex': False, 'text.fontangle': 'normal',
> 'patch.edgecolor': 'k', 'legend.labelspacing': 0.5, 'ps.useafm':
> False, 'mathtext.bf': 'serif:bold', 'lines.solid_joinstyle': 'round',
> 'font.monospace': ['Bitstream Vera Sans Mono', 'DejaVu Sans Mono',
> 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed',
> 'Terminal', 'monospace'], 'xtick.minor.size': 2,
> 'axes.formatter.limits': [-7, 7], 'figure.subplot.wspace':
> 0.20001, 'savefig.edgecolor': 'w', 'text.fontvariant':
> 'normal', 'image.cmap': 'jet', 'axes.edgecolor': 'k',
> 'tk.window_focus': False, 'image.origin': 'upper', 'text.fontsize':
> 'medium', 'font.serif': ['Times New Roman'], 'savefig.facecolor': 'w',
> 'maskedarray': 'obsolete', 'ytick.minor.size': 2, 'numerix':
> 'obsolete', 'font.stretch': 'normal', 'text.dvipnghack': None,
> 'ytick.color': 'k', 'lines.linestyle': '-', 'xtick.color': 'k',
> 'xtick.major.pad': 4, 'text.fontweight': 'normal', 'patch.facecolor':
> 'b', 'figure.figsize': [5.5996, 3.4609903369994113],
> 'axes.linewidth': 1.0, 'legend.handletextpad': 0.80004,
> 'mathtext.fallback_to_cm': True, 'lines.linewidth': 1.0,
> 'savefig.dpi': 100, 'verbose.fileo': 'sys.stdout',
> 'svg.image_noscale': False, 'docstring.hardcopy': False, 'font.size':
> 12.0, 'ps.fonttype': 3, 'path.simplify': True, 'polaraxes.grid': True,
> 'toolbar': 'toolbar2', 'pdf.compression': 6, 'grid.linewidth': 0.5,
> 'figure.autolayout': False, 'figure.facecolor': '0.75',
> 'ps.usedistiller': False, 'legend.isaxes': True, 'figure.edgecolor':
> 'w', 'mathtext.tt': 'monospace', 'contour.negative_linestyle':
> 'dashed', 'image.interpolation': 'bilinear', 'lines.markeredgewidth':
> 0.5, 'axes3d.grid': True, 'lines.marker': 'None', 'legend.shadow':
> False, 'axes.titlesize': 'large', 'backend': 'TkAgg',
> 'xtick.major.size': 4, 'legend.fontsize': 'large',
> 'lines.solid_capstyle': 'projecting', 'mathtext.it': 'serif:italic',
> 'font.variant': 'normal', 'xtick.labelsize': 8.0,
> 'axes.unicode_minus': True, 'ps.distiller.res': 6000, 'pdf.fonttype':
> 3, 'patch.linewidth': 1.0, 'pdf.inheritcolor': False,
> 'lines.dash_capstyle': 'butt', 'lines.color': 'b',
> 'text.latex.preview': False, 'figure.subplot.top':
> 0.90002, 'pdf.use14corefonts': False,
> 'legend.markerscale': 1.0, 'patch.antialiased': True, 'font.style':
> 'normal', 'backend_fallback': True, 'legend.fancybox': False,
> 'grid.linestyle': ':', 'axes.labelcolor': 'k', 'text.color': 'k',
> 'mathtext.rm': 'serif', 'legend.loc': 'upper right', 'interactive':
> True, 'cairo.format': 'png', 'savefig.orientation': 'portrait',
> 'axes.axisbelow': False, 'ytick.major.size': 4, 'axes.grid': False,
> 'plugins.directory': '.matplotlib_plugins', 'grid.color': 'k',
> 'timezone': 'UTC', 'ytick.major.pad': 4, 'legend.borderpad':
> 0.40002, 'lines.dash_joinstyle': 'round', 'datapath':
> '/usr/share/matplotlib/mpl-data', 'lines.antialiased': True,
> 'text.latex.unicode': False, 'image.lut': 256, 'units': False,
> 'figure.subplot.bottom': 0.10001, 'text.latex.preamble':
> [''], 'legend.numpoints': 2, 'legend.handlelength': 2.0,
> 'font.sans-serif': ['Bitstream Vera Sans', 'DejaVu Sans', 'Lucida
> Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant
> Garde', 'sans-serif'], 'font.family': 'serif', 'axes.labelsize':
> 'medium', 'ytick.minor.pad': 4, 'legend.borderaxespad': 0.5,
> 'mathtext.sf': 'sans\\-serif', 'axes.hold': True, 'verbose.level':
> 'silent', 'mathtext.default': 'regular', 'figure.subplot.left': 0.125,
> 'legend.columnspacing': 2.0, 'text.fontstyle': 'normal',
> 'font.weight': 'n

Re: [Matplotlib-users] collections?

2011-12-09 Thread Tony Yu
On Fri, Dec 9, 2011 at 2:13 PM, Daniel Hyams  wrote:

> I can't tell if I'm misusing collections here, or if there is a bug.
>  Anyway, what I'm trying to do is keep track of a group of rectangles
> generated from a bar plot.  Instead of letting there be a large number of
> artists added to the axes, I wanted to just group them into a collection
> and add the collection instead.  As in the code below:
>
> #!/usr/bin/env python
> import numpy
> import matplotlib.pyplot as plt
> import matplotlib.collections
>
> # just generate some data to plot
> x = numpy.linspace(0.0,2.0*numpy.pi,10)
> y = numpy.sin(x)
>
> # plot
> axes = plt.gca()
> bars = plt.bar(x,y,color='red',width=0.1)
>
> # strip out all of the newly inserted rectangles
>  for b in bars: b.remove()
>
> # and create a collection for plotting the rectangles instead.
> coll = matplotlib.collections.PatchCollection(bars)
>
> axes.artists.append(coll)
>
> plt.xlim(0.0,2.0*numpy.pi)
> plt.grid(True)
> plt.show()
>
> This appears to work at first blush, but if you resize the plot, you can
> tell that the rectangles are just fixed in their location now.  I tried
> messing around with setting the transform for the new collection object
> "coll" in different ways, to no avail.  Any suggestions welcome ;)
>
> --
> Daniel Hyams
> [email protected]
>
> try transOffset:

>>> coll = matplotlib.collections.PatchCollection(bars,
transOffset=axes.transData)

I've always found this a bit clumsy, but I think it's the standard way to
do it.

-Tony
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] collections?

2011-12-09 Thread Tony Yu
On Fri, Dec 9, 2011 at 4:11 PM, Daniel Hyams  wrote:

> I'm sorry, I should have stated the version.  I'm using 1.0.0, which just
> returns a list of rectangle artists.
>
>
> On Fri, Dec 9, 2011 at 4:08 PM, Benjamin Root  wrote:
>
>> On Fri, Dec 9, 2011 at 2:55 PM, Daniel Hyams  wrote:
>>
>>> Tried, but unfortunately it did not make any difference :(
>>>
>>>
>> Just as an interesting point... don't know if it means anything.  In
>> v1.1.x, we now return a "BarContainer" from the bar() function.  This
>> container subclasses the tuple type, which is why you are still able to
>> treat it like a list.  Anyway, this class does a bunch of things that I
>> wonder if it could be interfering with what you are trying to do.  Probably
>> not, but still...
>>
>> Ben Root
>>
>>
>
>
> --
> Daniel Hyams
> [email protected]
>

So I think the problem is that ``plt.bar`` assigns a transform to each
patch (as it should). But then when pass these patches to PatchCollection,
the collection applies it's own transform (but doesn't ignore the patch's
transform, apparently). The solution is to clear out the transform on each
patch---where "clearing" a transform translates to setting it to the
IdentityTransform.

Below is code that works *on my system*. It sounds like it will work
slightly differently on your system:

#!/usr/bin/env python
import numpy
import matplotlib.pyplot as plt
import matplotlib.collections
import matplotlib.transforms as transforms

# just generate some data to plot
x = numpy.linspace(0.0,2.0*numpy.pi,10)
y = numpy.sin(x)

# plot
axes = plt.gca()
bars = plt.bar(x,y,color='red',width=0.1)

axes.patches = []
for p in bars.patches:
p.set_transform(transforms.IdentityTransform())

## and create a collection for plotting the rectangles instead.
coll = matplotlib.collections.PatchCollection(bars.patches)

coll.set_transform(axes.transData)
axes.add_collection(coll, autolim=True)

plt.xlim(0.0,2.0*numpy.pi)
plt.grid(True)
plt.show()
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] collections?

2011-12-09 Thread Tony Yu
On Fri, Dec 9, 2011 at 5:23 PM, Tony Yu  wrote:

>
>
> On Fri, Dec 9, 2011 at 4:11 PM, Daniel Hyams  wrote:
>
>> I'm sorry, I should have stated the version.  I'm using 1.0.0, which just
>> returns a list of rectangle artists.
>>
>>
>> On Fri, Dec 9, 2011 at 4:08 PM, Benjamin Root  wrote:
>>
>>> On Fri, Dec 9, 2011 at 2:55 PM, Daniel Hyams  wrote:
>>>
>>>> Tried, but unfortunately it did not make any difference :(
>>>>
>>>>
>>> Just as an interesting point... don't know if it means anything.  In
>>> v1.1.x, we now return a "BarContainer" from the bar() function.  This
>>> container subclasses the tuple type, which is why you are still able to
>>> treat it like a list.  Anyway, this class does a bunch of things that I
>>> wonder if it could be interfering with what you are trying to do.  Probably
>>> not, but still...
>>>
>>> Ben Root
>>>
>>>
>>
>>
>> --
>> Daniel Hyams
>> [email protected]
>>
>
> So I think the problem is that ``plt.bar`` assigns a transform to each
> patch (as it should). But then when pass these patches to PatchCollection,
> the collection applies it's own transform (but doesn't ignore the patch's
> transform, apparently). The solution is to clear out the transform on each
> patch---where "clearing" a transform translates to setting it to the
> IdentityTransform.
>
> Below is code that works *on my system*. It sounds like it will work
> slightly differently on your system:
>
>
> #!/usr/bin/env python
> import numpy
> import matplotlib.pyplot as plt
> import matplotlib.collections
> import matplotlib.transforms as transforms
>
>
> # just generate some data to plot
> x = numpy.linspace(0.0,2.0*numpy.pi,10)
> y = numpy.sin(x)
>
> # plot
> axes = plt.gca()
> bars = plt.bar(x,y,color='red',width=0.1)
>
> axes.patches = []
> for p in bars.patches:
> p.set_transform(transforms.IdentityTransform())
>
> ## and create a collection for plotting the rectangles instead.
> coll = matplotlib.collections.PatchCollection(bars.patches)
>
> coll.set_transform(axes.transData)
> axes.add_collection(coll, autolim=True)
>
> plt.xlim(0.0,2.0*numpy.pi)
> plt.grid(True)
> plt.show()
>
>
>
P.S. you don't need the call to set_transform that I accidentally added.
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Speeding up pcolor plot

2011-12-20 Thread Tony Yu
On Tue, Dec 20, 2011 at 9:22 AM, Brad Malone  wrote:

> HI Paul,
>
> Thanks. I didn't realize it was that simple (appears that doing this
> essentially plots everything against integers in x and y). This will be a
> good backup plan if I can't get pcolor to work, although as you say, I'll
> have to fiddle around some with the axis formatters and such I suppose to
> get a good final plot out of this.
>
> Best,
> Brad
>
> On Tue, Dec 20, 2011 at 12:12 AM, Paul Ivanov wrote:
>
>> Hey again, Brad,
>>
>> Brad Malone, on 2011-12-19 23:44,  wrote:
>> > Hi, I am plotting a grid with pcolor. Below I've got a 1000x1000 grid.
>> >
>> > xi=linspace(-0.1,x[-1]+2,1000)
>> > > yi=linspace(-0.1,maxfreq+10,1000)
>> > > print 'Calling griddata...'
>> > > zi=griddata(x,y,z,xi,yi,interp='nn')
>> > > plt.pcolor(xi,yi,zi,cmap=plt.cm.hot)
>> ...
>> > How could I modify my above data (which is in xi,yi,and zi) to
>> > work with imshow (which seems to take 1 argument for data).
>>
>> Try either:
>>
>>  plt.matshow(zi,cmap=plt.cm.hot)
>>
>> or
>>
>>  plt.imshow(zi,cmap=plt.cm.hot)
>>
>> The first should be the quickest - it doesn't do any
>> fancy interpolation, and actually just passes some arguments to
>> the second. Using imshow directly, however, allows you to set a
>> different type of interpolation, should you desire it. If
>> you want xi and yi to be accurately reflect in the plot, you
>> might have to play around with changing the axis formatters
>> (though there might be an easier way of doing that, which escapes
>> me right now)
>>
>> best,
>> --
>> Paul Ivanov
>>
>
You may also want to try:

plt.pcolormesh(xi,yi,zi,cmap=plt.cm.hot)

If I remember correctly, pcolormesh is faster but a bit more restrictive.
(I think it's slower than matshow and imshow).

-Tony

P.S. I never knew about matshow; thanks Paul!
--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] An interactive plot challenge

2012-01-02 Thread Tony Yu
On Mon, Jan 2, 2012 at 6:01 AM, Virgil Stokes  wrote:

> The following link should link you to a very interesting graphical display,
>
>
> http://www.ecb.int/stats/exchange/eurofxref/html/eurofxref-graph-nok.en.html
>
> This type of graphical output (or at least something quite similar) can be
> found
> in other web pages that display financial data.
>
> Has anyone been able to produce a similar interactive graphical display
> using
> Matplotlib? A challenge for 2012 :-)
>
> --V
>

This shouldn't be too difficult. If you take a look at the event handling
examplesthere
are some good starting points. For example, the data
browser 
exampledoes
something similar, except you click to select data (you can change
this by hooking into 'motion_notify_event' instead of 'pick_event').

The one difficult part might be displaying your data-point info. Its easy
enough to just print out description to a terminal, but I'm not sure how
easy it is to display a tooltip. This SO
questionmay
help with that.

Best,
-Tony
--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fixed width - axis equal *and* tight

2012-01-03 Thread Tony Yu
On Tue, Jan 3, 2012 at 11:57 AM, Mario Fuest  wrote:

> Hi,
>
> Maybe a bad idea to ask a question on x-mas. Well, I hope it’s not that
> unpolite to push one‘s questions. :)
>
> Basically I just want to set a fixed width/height on my figure. That
> should be possible?
>
> Mario Fuest  schrieb am Sat, 24. Dec 16:42:
> > Hi there,
> >
> > I want to examine a vector field and therefore i used "quiver" to
> > visualize said field:
> >
> > > import numpy as np
> > > import matplotlib.pyplot as plt
> > >
> > > # points
> > > x, y = np.meshgrid(np.arange(0, 2*np.pi, 0.1),
> > >np.arange(0, 1*np.pi, 0.1))
> > > # derivatives
> > > dx = -2*np.sin(x)*np.cos(y)
> > > dy =np.cos(x)*np.sin(y)
> > >
> > > # plot
> > > plt.figure()
> > > plt.quiver(dx, dy, color='b')
> > >
> > > # beautiful axis
> > > a = plt.gca()
> > > x_a, y_a = a.get_xaxis(), a.get_yaxis()
> > > a.axis('tight')
> > > # TODO: We should not multiply with 10 here.
> > > x_a.set_ticks(np.arange(0, 2*np.pi*10+1, np.pi*10/4))
> > > y_a.set_ticks(np.arange(0, 1*np.pi*10+1, np.pi*10/4))
> > > labels = [
> > > r'$0$',
> > > r'$\frac{1}{4}\pi$',
> > > r'$\frac{1}{2}\pi$',
> > > r'$\frac{3}{4}\pi$',
> > > r'$\pi$',
> > > r'$\frac{5}{4}\pi$',
> > > r'$\frac{3}{2}\pi$',
> > > r'$\frac{7}{4}\pi$',
> > > r'$2 \pi$']
> > > a.set_xticklabels(labels)
> > > a.set_yticklabels(labels[:5])
> > >
> > > # show
> > > plt.show()
> >
> > (The plot looks like a double swirl, if anyone is interested in that
> > information)
> >
> > At first I do not know why I have to multiply with 10 at the ticks, but
> > thats not the point.
> >
> > It is much more important that I would like to set the image to a
> > certain width before saving. It should be both "tight" and "equal", so
> > after setting the width the height could be calculated automatically.
> >
> > As a workaround I use the images and strech them vertically, but then
> > the x/y axis tick labels look strange.
> >
> > So: How to set a certain width?
> >
> > Thanks and a merry Christmas,
> > Keba
>
>
You can try

>>> ax.set_aspect('equal')
>>> ax.autoscale(tight=True)

The order doesn't seem to matter.

-Tony
--
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Subplot x-tick labels overlap with each other and with titles

2012-01-04 Thread Tony Yu
On Wed, Jan 4, 2012 at 1:14 PM, jeffsp  wrote:

>
> I have been wondering the same thing.  Matlab is able to prevent labels
> from
> overlapping each other.  Why can't matplotlib?
>
>
> Chris Rodgers-7 wrote:
> >
> > Hi
> >
> > Whenever I create figures with at least 3x3 subplots, the x-tick
> > labels overlap with each other and they also overlap with the title of
> > the adjacent subplot, rendering the entire figure illegible. I know
> > that I can fine-tune the plot to look exactly the way I want with
> > "wspace" and "hspace" for instance, but I don't understand why this is
> > the default behavior. I wonder if I have a system font issue, such
> > that matplotlib thinks the fonts are smaller than they really are.
> >
> > My questions:
> > 1) Is this the intended behavior of matplotlib, or is there something
> > wrong with my installation?
> > 2) Assuming I don't have an installation issue, is there a very
> > general parameter I can change so that the overlap doesn't occur,
> > rather than manually adjusting every figure?
> >
> >
> > Minimal code to reproduce the problem:
> >
> > import numpy as np
> > import matplotlib.pyplot as plt
> > plt.figure()
> > plt.subplot(331)
> > plt.subplot(334)
> > plt.plot(np.arange(1))
> > plt.title('Title')
> > plt.show()
> >
> >
> > I'm attaching the output figure, although I'm not sure if the list
> > accepts attachments. The x-tick labels on subplot 334 overlap each
> > other, and the title of subplot 334 overlaps with the x-tick labels in
> > subplot 331.
>

Have you try calling `plt.tight_layout()` right before `plt.show()`?

-Tony

> >
> > System:
> > Ubuntu 10.04 x64
> > All packages are the stable versions from Synaptic, including ipython,
> > python, numpy, matplotlib 0.99.1.1
> > I've also tried the Enthought distribution with matplotlib 1.0.1 and
> > the results are the same
> > I've tried both "Wx" and "Tk" backends and the results are the same
> > I've tried `matplotlib.rcParams['xtick.labelsize'] = 'x-small'`, and
> > this does make the labels smaller, but for sufficiently large numbers
> > the overlap still occurs.
> >
> > Thanks for any help!
> > Chris
>
>
--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] cycling mechanism

2012-01-05 Thread Tony Yu
On Thu, Jan 5, 2012 at 11:51 AM, Benjamin Root  wrote:

>
>
> On Thu, Jan 5, 2012 at 7:56 AM, Jonathan Slavin 
> wrote:
>
>> Just one quick thought.  I hope that you will implement a longer default
>> color cycle than the current default.  I have several times run into
>> situations where I have to either modify the cycle or specify the colors
>> manually because I had more than 7 lines.
>
>
> Once the framework is in-place, that is certainly possible.  I agree that
> the current list is probably too short and could use 3 or 4 more values.
>
>
>>  Also, it'd be nice to have
>> the colors be as distinguishable as possible (at least early in the
>> cycle).
>
>
> Agreed.  Having blue and then green has always annoyed me.  However, I am
> hardly a color expert, and I would greatly welcome input from the peanut
> gallery (possibly from the same people pushing for a change in the default
> colormap?)
>

I guess this is sort of a tangential discussion, but, since you mentioned
it, I've attached a script showing my vote for a 11-color cycle. Also, I've
attached a script which shows all named colors defined by mpl.

-Tony


example_color_cycle.py
Description: Binary data


show_named_colors.py
Description: Binary data
--
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Horizontal bar chart with log x-axis, no filled boxes

2012-01-12 Thread Tony Yu
On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus wrote:

>
> On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote:
> > Does everything work correctly if it is vertical?  In other words, use
> bar() and set the y-axis to log scale? An example script would be useful.
>
> No, it doesn't appear to work as a vertical bar chart, either.
>
> I've attached a test case below.  The results I get running it with the
> X-axis as log are:
>
>http://thebuild.com/matlabtest/matlabtest-log.pdf
>
> Commenting out the call to ax.set_xscale('log') gives me:
>
>http://thebuild.com/matlabtest/matlabtest.pdf
>
> Thanks!
>
> --
>
> import numpy as np
> import matplotlib
> from matplotlib.font_manager import FontProperties
>
> import random
>
> matplotlib.use('PDF')
>
> import matplotlib.pyplot as plot
>
> small_font = FontProperties()
> small_font.set_size('xx-small')
>
> ind = np.arange(20)
>
> label = [ str(r) for r in ind ]
> data1 = [ float(random.random()*1) for r in ind ]
> data2 = [ float(random.random()*1) for r in ind ]
>
> width = 0.25
>
> fig = plot.figure()
> ax = fig.add_subplot(111)
>
> ax.set_title('Table Title')
> ax.set_xlabel('X Label')
>
> ax.barh(ind, data1, width, linewidth=0, color='blue')
> ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow')
> ax.set_yticks(ind + width/2)
> ax.set_yticklabels(label, fontproperties=small_font)
> ax.set_xscale('log')
>
> plot.savefig('matlabtest-log.pdf')
>
> --
> -- Christophe Pettus
>

Isn't this just because zero isn't defined in log scale? The second set of
data plots fine because it doesn't start at zero, but it isn't obvious what
to do with the first set of data. If you just want to make this work, you
can set the left parameter of the first `barh` call to some constant; for
example:

>>> origin = 10**np.floor(np.log10(np.min(data1)))
>>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue')

-Tony
--
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Horizontal bar chart with log x-axis, no filled boxes

2012-01-12 Thread Tony Yu
On Thu, Jan 12, 2012 at 12:14 PM, Benjamin Root  wrote:

>
>
> On Thu, Jan 12, 2012 at 11:04 AM, Tony Yu  wrote:
>
>>
>>
>> On Thu, Jan 12, 2012 at 11:39 AM, Christophe Pettus wrote:
>>
>>>
>>> On Jan 12, 2012, at 7:38 AM, Benjamin Root wrote:
>>> > Does everything work correctly if it is vertical?  In other words, use
>>> bar() and set the y-axis to log scale? An example script would be useful.
>>>
>>> No, it doesn't appear to work as a vertical bar chart, either.
>>>
>>> I've attached a test case below.  The results I get running it with the
>>> X-axis as log are:
>>>
>>>http://thebuild.com/matlabtest/matlabtest-log.pdf
>>>
>>> Commenting out the call to ax.set_xscale('log') gives me:
>>>
>>>http://thebuild.com/matlabtest/matlabtest.pdf
>>>
>>> Thanks!
>>>
>>> --
>>>
>>> import numpy as np
>>> import matplotlib
>>> from matplotlib.font_manager import FontProperties
>>>
>>> import random
>>>
>>> matplotlib.use('PDF')
>>>
>>> import matplotlib.pyplot as plot
>>>
>>> small_font = FontProperties()
>>> small_font.set_size('xx-small')
>>>
>>> ind = np.arange(20)
>>>
>>> label = [ str(r) for r in ind ]
>>> data1 = [ float(random.random()*1) for r in ind ]
>>> data2 = [ float(random.random()*1) for r in ind ]
>>>
>>> width = 0.25
>>>
>>> fig = plot.figure()
>>> ax = fig.add_subplot(111)
>>>
>>> ax.set_title('Table Title')
>>> ax.set_xlabel('X Label')
>>>
>>> ax.barh(ind, data1, width, linewidth=0, color='blue')
>>> ax.barh(ind, data2, width, left=data1, linewidth=0, color='yellow')
>>> ax.set_yticks(ind + width/2)
>>> ax.set_yticklabels(label, fontproperties=small_font)
>>> ax.set_xscale('log')
>>>
>>> plot.savefig('matlabtest-log.pdf')
>>>
>>> --
>>> -- Christophe Pettus
>>>
>>
>> Isn't this just because zero isn't defined in log scale? The second set
>> of data plots fine because it doesn't start at zero, but it isn't obvious
>> what to do with the first set of data. If you just want to make this work,
>> you can set the left parameter of the first `barh` call to some constant;
>> for example:
>>
>> >>> origin = 10**np.floor(np.log10(np.min(data1)))
>> >>> ax.barh(ind, data1, width, left=origin, linewidth=0, color='blue')
>>
>> -Tony
>>
>
> Right, but I could have sworn that we got this fixed at some point.  There
> is logic in the bar() function to detect logscale and handle it
> appropriately.  But I don't know what is not working here.
>
> Ben Root
>
>
Ahh, I didn't know this. It looks like setting `log=True` in `barh` works.

-Tony
--
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Grid problem?

2012-01-19 Thread Tony Yu
On Thu, Jan 19, 2012 at 12:44 AM, Paul Ivanov  wrote:

> Hi David,
>
> David Perlman, on 2012-01-06 16:57,  wrote:
> > Am I doing this wrong?  I am doing the best I can to follow the
> > documentation exactly.
>
> It doesn't look like you're doing it wrong - and your example
> works for me, though I'm not running OS X and can't verify that
> it works as it should on your chosen backend.
>
> Can anyone else who has OS X verify David's error? David, it'd be
> useful to know what your matplotlib.__version__ is, as well as
> whether or not the error occurs on the latest version, if that's
> possible.
>

> best,
> --
> Paul Ivanov
> 314 address only used for lists,  off-list direct email at:
> http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7
>


It seems to be version-specific. Works on my system (github HEAD).

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Path lacks initial MOVETO

2012-01-19 Thread Tony Yu
On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos  wrote:

> Hello everyone,
>
> I have been using matplotlib 0.99.3 to write some down. But I had to
> upgrade my OS and so installed the last version of the library 1.1.0. But
> unfortunately when I try to run my code I get the following error:
>  raise ValueError, 'Path lacks initial MOVETO'
> ValueError: Path lacks initial MOVETO
>
> I have been goggling it and saw some reports about it when using a vector
> containing zeros for which I apply a log and then trying to plot this. But
> the reports seem to indicate this was fixed in a svn version I can't access
> anymore.
> Can anyone point me on the correct direction to solve this problem?
>
> Thank you very much in advance,
> Bruno Santos
>
> Could you provide a bit more information: Are you calling `Path` directly?
If not, do you know what in your code is calling it? A minimal, runnable
example would be very helpful.

Cheers,
-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to create a movie?? (from matlab code)

2012-01-21 Thread Tony Yu
On Sat, Jan 21, 2012 at 9:07 AM, Gousios George wrote:

> Hello , i have the following code in matlab and trying to do it in
> matplotlib.
>
> I have this code in matlab (in a function showGraphs):
> ...
> m = size(myList, 3);
> for k = 1:m
> g = myList(:, :, k);
> image(g + 1)
> axis off
> axis square
> M(k) = getframe;
> end;
>
> and in another file (another function):
> ...
> M = showGraphs(grids)
> movie(M, 1)
>
>
>
> I did so far:
>
> def showGraphs(data):
> data=sc.array([data])
> n=sc.shape(data)[2]
> for k in range(n):
> mydata=data[:,:,k]
> #plt.imshow(mydata+1)-->> this doesn't work
>
> Also ,in order to do the animation :
>
> grids=...(result from another function)
> result=showGraph(grids)
> fig=plt.figure()
> ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
> plt.show()
>
> Right now the program says "TypeError: 'NoneType' object is not
> callable" (it has errors in the animation call)
>
> What should be my approach to this in order to have the animation?
>
> Thank you!
>
>
You're getting that error because the second argument to FuncAnimation
(`result` in your example) should be a function (not always; see example 2
linked below). Right now, if your `showGraphs` function is defined in full,
it returns a value of None, which gets saved to `result` (hence the error).

You should take a look at some of the image animation examples
(ex1,
ex2
).

-Tony
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to create a movie?? (from matlab code)

2012-01-21 Thread Tony Yu
On Sat, Jan 21, 2012 at 11:31 AM, Gousios George wrote:

> **
> Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε:
>
>
>
> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George wrote:
>
>> Hello , i have the following code in matlab and trying to do it in
>> matplotlib.
>>
>> I have this code in matlab (in a function showGraphs):
>> ...
>> m = size(myList, 3);
>> for k = 1:m
>> g = myList(:, :, k);
>> image(g + 1)
>> axis off
>> axis square
>> M(k) = getframe;
>> end;
>>
>> and in another file (another function):
>> ...
>> M = showGraphs(grids)
>> movie(M, 1)
>>
>>
>>
>> I did so far:
>>
>> def showGraphs(data):
>> data=sc.array([data])
>> n=sc.shape(data)[2]
>> for k in range(n):
>> mydata=data[:,:,k]
>> #plt.imshow(mydata+1)-->> this doesn't work
>>
>> Also ,in order to do the animation :
>>
>> grids=...(result from another function)
>> result=showGraph(grids)
>> fig=plt.figure()
>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
>> plt.show()
>>
>> Right now the program says "TypeError: 'NoneType' object is not
>> callable" (it has errors in the animation call)
>>
>> What should be my approach to this in order to have the animation?
>>
>> Thank you!
>>
>>
> You're getting that error because the second argument to FuncAnimation
> (`result` in your example) should be a function (not always; see example 2
> linked below). Right now, if your `showGraphs` function is defined in full,
> it returns a value of None, which gets saved to `result` (hence the error).
>
> You should take a look at some of the image animation examples 
> (ex1<http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>,
> ex2<http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>
> ).
>
> -Tony
>
>
> I did now :
>
>
> def showGraphs(data):
> data=sc.array([data])
> n=sc.shape(data)[2]
> ims=[]
>
> for k in range(n):
> mydata=data[:,:,k]
> im=plt.imshow(mydata+1)
> ims.append([im])
> return ims
>
> and now it gives me "TypeError: Invalid dimensions for image data.
>
>
Please post short, but executable examples when possible. I'm not sure what
your data looks like, but your call to `sc.array` is strange (I'm not sure
why you have square brackets, which effectively adds an unnecessary
dimension to your data).

The code attached below should work.

Cheers,
-Tony

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import ArtistAnimation


fig = plt.figure()

def showGraphs(data):
data = np.asarray(data) # unnecessary in this example
n = np.shape(data)[2]

ims = []
#for mydata in np.rollaxis(data, -1):
for k in range(n):
mydata = data[:, :, k]
im = plt.imshow(mydata)
ims.append([im])
return ims

# 5 frames of a random 20 x 20 image
data = np.random.uniform(size=(20, 20, 5))
ims = showGraphs(data)

ani = ArtistAnimation(fig, ims)
plt.show()
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Path lacks initial MOVETO

2012-01-23 Thread Tony Yu
On Mon, Jan 23, 2012 at 9:56 AM, Michael Droettboom  wrote:

>  I have a solution for this in this pull request:
>
> https://github.com/matplotlib/matplotlib/pull/684
>
> If able, would you mind confirming that it addresses your issue?
>
> Mike
>
>
This fix worked on my system.
-Tony


>
> On 01/23/2012 09:02 AM, Bruno Santos wrote:
>
> Sorry it took me a while to get back to you. I have finally written some
> code to replicate the problem. I have attached a file with it.
>
>  Thank you very much in advance,
> Bruno Santos
>
>  2012/1/19 Tony Yu 
>
>>
>>
>>  On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos wrote:
>>
>>> Hello everyone,
>>>
>>>  I have been using matplotlib 0.99.3 to write some down. But I had to
>>> upgrade my OS and so installed the last version of the library 1.1.0. But
>>> unfortunately when I try to run my code I get the following error:
>>>  raise ValueError, 'Path lacks initial MOVETO'
>>> ValueError: Path lacks initial MOVETO
>>>
>>>  I have been goggling it and saw some reports about it when using a
>>> vector containing zeros for which I apply a log and then trying to plot
>>> this. But the reports seem to indicate this was fixed in a svn version I
>>> can't access anymore.
>>> Can anyone point me on the correct direction to solve this problem?
>>>
>>>  Thank you very much in advance,
>>>  Bruno Santos
>>>
>>>   Could you provide a bit more information: Are you calling `Path`
>> directly? If not, do you know what in your code is calling it? A minimal,
>> runnable example would be very helpful.
>>
>> Cheers,
>> -Tony
>>
>>
>
>
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe 
> now!http://p.sf.net/sfu/learndevnow-dev2
>
>
>
> ___
> Matplotlib-users mailing 
> [email protected]://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
>
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to create a movie?? (from matlab code)

2012-01-23 Thread Tony Yu
2012/1/23 Gousios George 

> **
> Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε:
>
> Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε:
>
>
>
> On Sat, Jan 21, 2012 at 11:31 AM, Gousios George wrote:
>
>>  Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε:
>>
>>
>>
>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George wrote:
>>
>>> Hello , i have the following code in matlab and trying to do it in
>>> matplotlib.
>>>
>>> I have this code in matlab (in a function showGraphs):
>>> ...
>>> m = size(myList, 3);
>>> for k = 1:m
>>> g = myList(:, :, k);
>>> image(g + 1)
>>> axis off
>>> axis square
>>> M(k) = getframe;
>>> end;
>>>
>>> and in another file (another function):
>>> ...
>>> M = showGraphs(grids)
>>> movie(M, 1)
>>>
>>>
>>>
>>> I did so far:
>>>
>>> def showGraphs(data):
>>> data=sc.array([data])
>>> n=sc.shape(data)[2]
>>> for k in range(n):
>>> mydata=data[:,:,k]
>>> #plt.imshow(mydata+1)-->> this doesn't work
>>>
>>> Also ,in order to do the animation :
>>>
>>> grids=...(result from another function)
>>> result=showGraph(grids)
>>> fig=plt.figure()
>>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
>>> plt.show()
>>>
>>> Right now the program says "TypeError: 'NoneType' object is not
>>> callable" (it has errors in the animation call)
>>>
>>> What should be my approach to this in order to have the animation?
>>>
>>> Thank you!
>>>
>>>
>> You're getting that error because the second argument to FuncAnimation
>> (`result` in your example) should be a function (not always; see example 2
>> linked below). Right now, if your `showGraphs` function is defined in full,
>> it returns a value of None, which gets saved to `result` (hence the error).
>>
>> You should take a look at some of the image animation examples 
>> (ex1<http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>,
>> ex2<http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>
>> ).
>>
>> -Tony
>>
>>
>>  I did now :
>>
>>
>> def showGraphs(data):
>> data=sc.array([data])
>> n=sc.shape(data)[2]
>>  ims=[]
>>
>> for k in range(n):
>> mydata=data[:,:,k]
>>  im=plt.imshow(mydata+1)
>> ims.append([im])
>> return ims
>>
>> and now it gives me "TypeError: Invalid dimensions for image data.
>>
>>
> Please post short, but executable examples when possible. I'm not sure
> what your data looks like, but your call to `sc.array` is strange (I'm not
> sure why you have square brackets, which effectively adds an unnecessary
> dimension to your data).
>
> The code attached below should work.
>
> Cheers,
> -Tony
>
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib.animation import ArtistAnimation
>
>
> fig = plt.figure()
>
> def showGraphs(data):
> data = np.asarray(data) # unnecessary in this example
> n = np.shape(data)[2]
>
> ims = []
> #for mydata in np.rollaxis(data, -1):
> for k in range(n):
> mydata = data[:, :, k]
> im = plt.imshow(mydata)
> ims.append([im])
> return ims
>
> # 5 frames of a random 20 x 20 image
> data = np.random.uniform(size=(20, 20, 5))
> ims = showGraphs(data)
>
> ani = ArtistAnimation(fig, ims)
> plt.show()
>
> Now,it gives me 2 figures (why 2?) but empty.(maybe i didn't convert right
> the matlab code below?)
> The data in the showGraphs function is the result from this function (in
> matlab):
> .
> grids = zeros(n, n, t + 1);
> grids(:, :, 1) = rest;
> for i = 2:(t + 1)
> Extended = extendLat1(rest);
> rest = applyExtended(Extended);
> grids(:, :, i) = rest;
> end;
>
> And i did this in python:
>
>grids=sc.zeros((area,area,t+1))
> rest=grids[:,:,0]
> for i in range(1,t):
> extended=extend(rest)
> rest=apply_extend(extended)
> grids[:,:,i]=rest
> return grids
>
> Thanks for helping!
>
>  Any help?Thanks!
>
> Sorry, but could you be a bit clearer:
* Did the example I provide work for you?
* Assuming it did, are you essentially replacing `data` in my example with
`grids` in this most recent example?
* I don't get 2 figures: are you asking about the code from my last message?
* Please provide a minimal, *executable* example

-Tony
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to create a movie?? (from matlab code)

2012-01-23 Thread Tony Yu
2012/1/23 Gousios George 

> **
> Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε:
>
>
>
> 2012/1/23 Gousios George 
>
>>  Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε:
>>
>> Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε:
>>
>>
>>
>> On Sat, Jan 21, 2012 at 11:31 AM, Gousios George 
>> wrote:
>>
>>>  Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε:
>>>
>>>
>>>
>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George 
>>> wrote:
>>>
>>>> Hello , i have the following code in matlab and trying to do it in
>>>> matplotlib.
>>>>
>>>> I have this code in matlab (in a function showGraphs):
>>>> ...
>>>> m = size(myList, 3);
>>>> for k = 1:m
>>>> g = myList(:, :, k);
>>>> image(g + 1)
>>>> axis off
>>>> axis square
>>>> M(k) = getframe;
>>>> end;
>>>>
>>>> and in another file (another function):
>>>> ...
>>>> M = showGraphs(grids)
>>>> movie(M, 1)
>>>>
>>>>
>>>>
>>>> I did so far:
>>>>
>>>> def showGraphs(data):
>>>> data=sc.array([data])
>>>> n=sc.shape(data)[2]
>>>> for k in range(n):
>>>> mydata=data[:,:,k]
>>>> #plt.imshow(mydata+1)-->> this doesn't work
>>>>
>>>> Also ,in order to do the animation :
>>>>
>>>> grids=...(result from another function)
>>>> result=showGraph(grids)
>>>> fig=plt.figure()
>>>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
>>>> plt.show()
>>>>
>>>> Right now the program says "TypeError: 'NoneType' object is not
>>>> callable" (it has errors in the animation call)
>>>>
>>>> What should be my approach to this in order to have the animation?
>>>>
>>>> Thank you!
>>>>
>>>>
>>> You're getting that error because the second argument to FuncAnimation
>>> (`result` in your example) should be a function (not always; see example 2
>>> linked below). Right now, if your `showGraphs` function is defined in full,
>>> it returns a value of None, which gets saved to `result` (hence the error).
>>>
>>> You should take a look at some of the image animation examples 
>>> (ex1<http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>,
>>> ex2<http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>
>>> ).
>>>
>>> -Tony
>>>
>>>
>>>  I did now :
>>>
>>>
>>> def showGraphs(data):
>>> data=sc.array([data])
>>> n=sc.shape(data)[2]
>>>  ims=[]
>>>
>>> for k in range(n):
>>> mydata=data[:,:,k]
>>>  im=plt.imshow(mydata+1)
>>> ims.append([im])
>>> return ims
>>>
>>> and now it gives me "TypeError: Invalid dimensions for image data.
>>>
>>>
>> Please post short, but executable examples when possible. I'm not sure
>> what your data looks like, but your call to `sc.array` is strange (I'm not
>> sure why you have square brackets, which effectively adds an unnecessary
>> dimension to your data).
>>
>> The code attached below should work.
>>
>> Cheers,
>> -Tony
>>
>> import numpy as np
>> import matplotlib.pyplot as plt
>> from matplotlib.animation import ArtistAnimation
>>
>>
>> fig = plt.figure()
>>
>> def showGraphs(data):
>> data = np.asarray(data) # unnecessary in this example
>> n = np.shape(data)[2]
>>
>> ims = []
>> #for mydata in np.rollaxis(data, -1):
>> for k in range(n):
>> mydata = data[:, :, k]
>> im = plt.imshow(mydata)
>> ims.append([im])
>> return ims
>>
>> # 5 frames of a random 20 x 20 image
>> data = np.random.uniform(size=(20, 20, 5))
>> ims = showGraphs(data)
>>
>> ani = ArtistAnimation(fig, ims)
>> plt.show()
>>
>> Now,it gives me 2 figures (why 2?) but empty.(maybe i didn't convert
>> right the matlab code below?)
>> The data in the showGraphs function is the result from this function (in
>> matlab):
>> .
>> grids = zeros(n, n, t + 1);
>> 

Re: [Matplotlib-users] How to create a movie?? (from matlab code)

2012-01-23 Thread Tony Yu
2012/1/23 Gousios George 

> **
> Στις 23/01/2012 08:10 μμ, ο/η Benjamin Root έγραψε:
>
> 2012/1/23 Gousios George 
>
>>  Στις 23/01/2012 07:48 μμ, ο/η Tony Yu έγραψε:
>>
>>
>>
>> 2012/1/23 Gousios George 
>>
>>>  Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε:
>>>
>>>
>>>
>>> 2012/1/23 Gousios George 
>>>
>>>>  Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε:
>>>>
>>>> Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε:
>>>>
>>>>
>>>>
>>>> On Sat, Jan 21, 2012 at 11:31 AM, Gousios George >>> > wrote:
>>>>
>>>>>  Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε:
>>>>>
>>>>>
>>>>>
>>>>> On Sat, Jan 21, 2012 at 9:07 AM, Gousios George >>>> > wrote:
>>>>>
>>>>>> Hello , i have the following code in matlab and trying to do it in
>>>>>> matplotlib.
>>>>>>
>>>>>> I have this code in matlab (in a function showGraphs):
>>>>>> ...
>>>>>> m = size(myList, 3);
>>>>>> for k = 1:m
>>>>>> g = myList(:, :, k);
>>>>>> image(g + 1)
>>>>>> axis off
>>>>>> axis square
>>>>>> M(k) = getframe;
>>>>>> end;
>>>>>>
>>>>>> and in another file (another function):
>>>>>> ...
>>>>>> M = showGraphs(grids)
>>>>>> movie(M, 1)
>>>>>>
>>>>>>
>>>>>>
>>>>>> I did so far:
>>>>>>
>>>>>> def showGraphs(data):
>>>>>> data=sc.array([data])
>>>>>> n=sc.shape(data)[2]
>>>>>> for k in range(n):
>>>>>> mydata=data[:,:,k]
>>>>>> #plt.imshow(mydata+1)-->> this doesn't work
>>>>>>
>>>>>> Also ,in order to do the animation :
>>>>>>
>>>>>> grids=...(result from another function)
>>>>>> result=showGraph(grids)
>>>>>> fig=plt.figure()
>>>>>> ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
>>>>>> plt.show()
>>>>>>
>>>>>> Right now the program says "TypeError: 'NoneType' object is not
>>>>>> callable" (it has errors in the animation call)
>>>>>>
>>>>>> What should be my approach to this in order to have the animation?
>>>>>>
>>>>>> Thank you!
>>>>>>
>>>>>>
>>>>> You're getting that error because the second argument to FuncAnimation
>>>>> (`result` in your example) should be a function (not always; see example 2
>>>>> linked below). Right now, if your `showGraphs` function is defined in 
>>>>> full,
>>>>> it returns a value of None, which gets saved to `result` (hence the 
>>>>> error).
>>>>>
>>>>> You should take a look at some of the image animation examples 
>>>>> (ex1<http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>,
>>>>> ex2<http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>
>>>>> ).
>>>>>
>>>>> -Tony
>>>>>
>>>>>
>>>>>  I did now :
>>>>>
>>>>>
>>>>> def showGraphs(data):
>>>>> data=sc.array([data])
>>>>> n=sc.shape(data)[2]
>>>>>  ims=[]
>>>>>
>>>>> for k in range(n):
>>>>> mydata=data[:,:,k]
>>>>>  im=plt.imshow(mydata+1)
>>>>> ims.append([im])
>>>>> return ims
>>>>>
>>>>> and now it gives me "TypeError: Invalid dimensions for image data.
>>>>>
>>>>>
>>>> Please post short, but executable examples when possible. I'm not sure
>>>> what your data looks like, but your call to `sc.array` is strange (I'm not
>>>> sure why you have square brackets, which effectively adds an unnecessary
>>>> dimension to your data).
>>>>
>>>> The code attached below should work.
>>>>
>&

Re: [Matplotlib-users] beginner examples using matplotlib.transforms?

2012-01-23 Thread Tony Yu
On Mon, Jan 23, 2012 at 2:43 PM, reckoner  wrote:

> Hi,
>
> I am trying to create a sequence of rotated rectangles of various
> sizes/orientations.  I have been looking at the following page:
>
> http://matplotlib.sourceforge.net/devel/transformations.html
>
> But I can't find any examples of how to use these transformations and
> then show the resulting figures. I am trying to create a sequence of
> frames for a rectangle tumbling forward. This means I would need to
> daisychain the transformations noted above.
>
> Any help getting started would be greatly appreciated!
>
>
Have you seen the Transformations
Tutorial?
It has a number of usage examples.

Cheers,
-Tony
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Problem with cachedRenderer

2012-01-25 Thread Tony Yu
On Wed, Jan 25, 2012 at 7:14 AM, andi  wrote:

>  Hi Tony,
>
> thanks for your reply! I am not using the pdf backend, but the GTKAgg
> backend. Is it working with this backend in the development version?
>
> Cheers
> Andi
>

Hi Andi,

Unfortunately, I can't run the GTKAgg backend, but I checked your code
snippet on the backends I have on my system. It seems this behavior is
really inconsistent:

Works:
* agg
* qt4agg
* tkagg

Doesn't work:
* pdf
* macosx

To be honest, I don't understand the magical workings of the backends very
well. I've copied the developer list since the consistency of backends
seems like a relevant issue.

-Tony

P.S. Andi: Be sure to "reply all" since the mailing list doesn't
automatically do this for some reason.


>
> On 25/01/12 00:26, Tony Yu wrote:
>
>
>
> On Tue, Jan 24, 2012 at 12:53 PM, andi  wrote:
>
>> Hi all,
>>
>> I have some old custom code for generating videos from matplotlib (not
>> using the animation module). It used to work, but is now failing.
>> Here is what I am doing:
>>
>> ---
>> import matplotlib.pyplot as plt
>> import numpy as np
>>
>> fig = plt.figure()
>> ax = fig.add_subplot(111)
>> im = ax.imshow(np.zeros((100, 100)))
>> fig.canvas.draw()
>> ax.draw_artist(im)
>> --
>>
>> ... and draw_artist from axes.py then gives me an AssertionError because
>> no renderer is found (assert self._cachedRenderer is not None).
>>
>> Right now I am using matplotlib 1.0.1 and I think that the above used to
>> work with older versions in matplotlib. See e.g.
>>
>> http://www.mail-archive.com/[email protected]/msg06598.html
>>
>> Any ideas?
>>
>> Cheers
>> Andi
>>
>>
> Hi Andi,
>
> I'm running a development version of matplotlib, and your code runs
> without issue. That doesn't really solve your issue, but it means that it's
> not due to deprecation.
>
> On a hunch, I tried running the code with
> >>> import matplotlib
> >>> matplotlib.use('pdf')
> at the top of the file, and I got the same error. Not really sure why,
> though. Do you happen to have the pdf backend set as the default?
>
> -Tony
>
>
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] colorbar.py bug in matplotlib 1.1.0?

2012-01-25 Thread Tony Yu
On Wed, Jan 25, 2012 at 2:42 PM, Josh Hemann wrote:

> I have some code that has worked in matplotlib versions 0.99 and 1.0.1.
> Recently, I updated to 1.1.0 and my code broke, specifically in a call to
> colorbar(). I tried running this gallery 
> exampleand
>  get the same error. Here is the snippet: The
> error results from the first call to colorbar in the example, which is cbar
> = fig.colorbar(cax, ticks=[-1, 0, 1]) My internet searches have not
> revealed anything yet. Has anyone seen or reported this issue? Any clean
> work-arounds?
> Josh Hemann
>
>
> Hi Josh,

Do you get the error with the gallery example, or some modified version of
it? The example runs fine on my system (but I'm on a more recent
development version).

Is there any chance that your installation got screwed up? How did you
upgrade?

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Using Proxy Artist to make legend

2012-01-26 Thread Tony Yu
On Thu, Jan 26, 2012 at 8:20 AM, Sabine van der Linden wrote:

> Hello,
>
> I have made a plot with a fill_between part, which does not show up in the
> legend. I have read that I have to use a proxy artist for this, but I have
> no
> clue where to place this, and how.. The fill between works fine, it's just
> the
> legend that is not really cooperating ;)
>
> import matplotlib.pyplot as plt
>
> plt.plot(dbx, gemlist)
> plt.title('Reekslengte '+str(i))
> plt.xlabel('signaal-ruisverhouding ingangssignaal (dB)')
> plt.ylabel('signaal-ruisverhouding uitgangssignaal (dB)')
> plt.xlim(-36, 22)
>
> plt.fill_between(dbx, boven, onder, color='b', alpha=0.1)
> plt.legend(loc=4)
> plt.show()
>
> Tnx in advance :)
>
> Sabine
>
>
I have a convenience function (copied below) in my python path that I like
to use for this purpose.

Hope that helps,
-Tony

#

def fill_between(x, y1, y2=0, ax=None, **kwargs):
"""Plot filled region between `y1` and `y2`.

This function works exactly the same as matplotlib's fill_between,
except
that it also plots a proxy artist (specifically, a rectangle of 0 size)
so that it can be added it appears on a legend.
"""
ax = ax if ax is not None else plt.gca()
ax.fill_between(x, y1, y2, **kwargs)
p = plt.Rectangle((0, 0), 0, 0, **kwargs)
ax.add_patch(p)
return p
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Overlaying part of an matrix image on another.

2012-01-27 Thread Tony Yu
On Fri, Jan 27, 2012 at 9:13 AM, Pål Gunnar Ellingsen wrote:

> Hi
>
> I have a array, M, which is (4Nx4M), and an array (image), im, which is
> NxM.
> I can currently plot the matrix as a 2d image using imshow using:
>
> import matplotlib.pyplot as plt
> from matplotlib import cm
>
> # some code for reading in the matrix
>
> cmap = cm.get_cmap('jet', 256)
> imM = plt.imshow(M, cmap=cmap, vmin= -1, vmax=1)
>
> But now i would like to plot im on top of M, such that it covers the firs
> element of M.
> If I do
>
> plt.hold()
> plt.imshow(im)
>
> I only see im, and not M. I'm used to doing this in Matlab, where this
> would work.
>
> Can anyone explain me what I'm doing wrong?
>
>
> Kind Regards
>

A call to `plt.autoscale` should fix your problem. It looks like `imshow`
rescales the axes limits to the current image limits, instead of the limits
for all the data in the axes. (Executable example below; note, axes "hold"
by default, so it's not necessary to call hold).

-Tony



import numpy as np
import matplotlib.pyplot as plt

background = np.random.uniform(0, 255, size=(20, 20))
overlay = np.arange(25).reshape((5, 5))

plt.imshow(background, interpolation='nearest', cmap=plt.cm.gray)
plt.imshow(overlay, cmap=plt.cm.jet, alpha=0.5)
# You could also replace this with `plt.axis([0, 20, 0, 20])
plt.autoscale()
plt.show()
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Events

2012-01-27 Thread Tony Yu
On Fri, Jan 27, 2012 at 5:54 AM, Jerzy Karczmarczuk <
[email protected]> wrote:

> Benjamin Root answers my query concerning user-generated events :
> > To answer your question, take a look at how pick_event() is declared
> > in backend_bases.py:
> >
> > def pick_event(self, mouseevent, artist, **kwargs):
> >  ...
> > self.callbacks.process(s, event)
> >
> > The function that "fires" the event is "self.callbacks.process(s,
> > event)", where "self" is the figure canvas.
> Dear Ben, thank you, but this is not exactly my problem. I don't want to
> call the callback myself, since the event should be "fired" from within
> a callback. I should have been more precise. Let's distil the problem.
> [This is a part of my current teaching...] I did already what you
> suggest here...
>
> Imagine an animation, which consists in generating a trajectory, segment
> after segment (say, of a planet). Classically this is a loop, but when
> it runs, the rest of the program is blocked. So, instead, the code
> behaves as a Python generator, generates just one segment, and that's
> all. But it "yields" something, it posts an event, put it in a queue,
> and somebody else, the mainloop() or similar, pops it off the queue and
> re-launches the callback. (With generators, it calls the .next()). No
> timers, as in Timer or Funct animations...
>
> It must be "decentralized", no recursive calls. My callback from time to
> time creates another planet, or destroys an existent, and there are
> simultaneous trajectories on the screen, several concurrent events in
> the queue. And the system should remain reactive, interpret buttons,
> sliders, etc.
>
> I know how to do this by hand, how to write my own event loop, declare a
> queue, and how to add to my private "virtual" event handling also the
> callbacks of mouse events. But this is an overkill, I  repeat the
> functionalities which are already there, the event queue in particular.
>
> I did it with wx. But Matplotlib protects the user from the concrete
> back-end, and I want to protect my students as well, so I look for a
> "GUI-neutral" solution.
>
> Thanks.
>
> Jerzy
>

I'm not sure if this matches your use case, but have you looked into using
a coroutine. (I only recently learned about them---see presentation slides
linked on this page . So obviously I'm
going out of my way to find a use case :)

I've attached a simple example below.

-Tony

#~~~

import matplotlib.pyplot as plt
import numpy as np


def datalistener():
fig, ax = plt.subplots()
line, = ax.plot(0, 0, 'o-')
i = 1
while True:
y0 = yield
x = np.hstack((line.get_xdata(), i))
y = np.hstack((line.get_ydata(), y0))
line.set_data((x, y))
ax.update_datalim(np.transpose((x, y)))
ax.autoscale_view()
plt.draw()
i += 1


plt.ion()
plotdata = datalistener()
# initialize the coroutine
plotdata.next()
while True:
y = raw_input('enter data point: ')
try:
plotdata.send(float(y))
except:
break
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histogram plots color range

2012-01-27 Thread Tony Yu
On Fri, Jan 27, 2012 at 11:27 AM, nahren manuel wrote:

> Hello ,
> I have a two dimensional array, 40X20(rowsXcolumns). Each of the 40 rows
> themselves hold values of the bins of a distribution (which is not always
> normal, can expect a bimodal curve as well)
> It is little difficult to explain to I actually created a sample figure:
> http://www.flickr.com/photos/nahrenmascarenhas/6771369071/in/photostream
>
> Any help or trick will be very useful
>
> loads of thanks
>
> nahren
>

This plot seems similar to something I wanted to do (and asked the list
about).
I ended up getting something to work, but the code is a bit ugly. I've
attached my most recent version (which probably needs some cleaning up, but
it works).

If you want a continuous field instead of distinct bars (like you have in
your sample image), you may be able to write up something that's a little
simpler by sectioning out the columns an array into strips of equal width
and repeating histogram values across those columns (sorry, this is a bit
vague). Then use `imshow` to plot the array.

-Tony


histstrip.py
Description: Binary data
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] histogram plots color range

2012-01-27 Thread Tony Yu
On Fri, Jan 27, 2012 at 4:01 PM,  wrote:

> On Fri, Jan 27, 2012 at 12:18 PM, Tony Yu  wrote:
> >
> >
> > On Fri, Jan 27, 2012 at 11:27 AM, nahren manuel 
> > wrote:
> >>
> >> Hello ,
> >> I have a two dimensional array, 40X20(rowsXcolumns). Each of the 40 rows
> >> themselves hold values of the bins of a distribution (which is not
> always
> >> normal, can expect a bimodal curve as well)
> >> It is little difficult to explain to I actually created a sample figure:
> >>
> http://www.flickr.com/photos/nahrenmascarenhas/6771369071/in/photostream
> >>
> >> Any help or trick will be very useful
> >>
> >> loads of thanks
> >>
> >> nahren
> >
> >
> > This plot seems similar to something I wanted to do (and asked the list
> > about). I ended up getting something to work, but the code is a bit ugly.
> > I've attached my most recent version (which probably needs some cleaning
> up,
> > but it works).
> >
> > If you want a continuous field instead of distinct bars (like you have in
> > your sample image), you may be able to write up something that's a little
> > simpler by sectioning out the columns an array into strips of equal width
> > and repeating histogram values across those columns (sorry, this is a bit
> > vague). Then use `imshow` to plot the array.
>
> Looks nice.
>
> Given that it is too specialized for matplotlib, it would be an
> interesting addition to violin and bean plots in scikits.statsmodels
> if you don't mind that we borrow it (scikits.statsmodels is BSD
> licensed).
>
> Thanks,
>
> Josef
>
>
Sure thing---I'm happy to contribute. The code probably needs to be cleaned
up, but unfortunately, I have little motivation since I don't use it
anymore. Feel free to do whatever you like with it.

Cheers,
-Tony
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] (no subject)

2012-01-29 Thread Tony Yu
On Sun, Jan 29, 2012 at 2:21 AM, Paul Hobson  wrote:

> There is undoubtedly a more efficient way to do this, but give this a shot:
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> x = np.arange(0, 10.5, 0.5)
> y = -3.0*x + 0.5*x**2
>
> color_list = ['FireBrick', 'Orange', 'DarkGreen', 'DarkBlue', 'Indigo']
> limits = np.arange(0, 11, 2)
> fig, ax1 = plt.subplots()
> for n, color in enumerate(color_list):
>lower = np.where(x >= limits[n])[0]
>upper = np.where(x <= limits[n+1])[0]
>index = np.intersect1d(lower, upper)
>ax1.plot(x[index], y[index], linestyle='-', color=color, linewidth=2)
>
> plt.show()
>
> HTH,
> -paul
>

Alternatively, you could replace the loop above with::

indexes = np.searchsorted(x, limits)
# add 1 to end index so that segments overlap
for i0, i1, color in zip(indexes[:-1], indexes[1:]+1, color_list):
ax1.plot(x[i0:i1], y[i0:i1], linestyle='-', color=color,
linewidth=2)

This is not much different than Paul's example---just whatever you find
more readable.

-Tony


>
> On Fri, Jan 27, 2012 at 8:12 AM, nahren manuel 
> wrote:
> > Dear Users,
> > I want to plot a XY, the X-value is constant, but let assume Y varees
> from
> > 1-10, so I want o have different colors accordingly for the range
> > 0-2,2-4,4-6,6-8,8-10.
> >
> > thanks a lot
> > najren
> >
> >
> --
> > Try before you buy = See our experts in action!
> > The most comprehensive online learning library for Microsoft developers
> > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> > Metro Style Apps, more. Free future releases when you subscribe now!
> > http://p.sf.net/sfu/learndevnow-dev2
> > ___
> > Matplotlib-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
>
>
> --
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Subplot x-tick labels overlap with each other and with titles

2012-01-30 Thread Tony Yu
On Sun, Jan 29, 2012 at 10:10 PM, C M  wrote:

>
>
> On Wed, Jan 4, 2012 at 2:19 PM, Benjamin Root  wrote:
>
>>
>>
>> On Wednesday, January 4, 2012, jeffsp  wrote:
>> >
>> > plt.tight_layout(), sweet
>> >
>> > it still makes the labels too close to read, even if they don't overlap.
>> > that is, they're just a continuous string of numbers with no whitespace
>> > between.
>> >
>> > it does clean up the rest of the plot really nicely, though, without
>> having
>> > to continually dick around with subplots_adjust
>> >
>> >
>>
>> Well, it is a new feature with plenty of room for improvements.  Maybe
>> some sort of mindist parameter would be useful to establish a minimum
>> distance between text objects?
>>
>> Ben Root
>>
>>
> Something like that sounds good.  If there were a way to make it the
> default that labels would never overlap (but that default could be toggled
> for those who, somehow, want to not be able to read their labels?), that
> strikes me as best.
>
> In the meantime, what are other ways to do this?
>
>
Just to clarify, I don't think improvements to `tight_layout` will fix your
issues with tick layout; `tight_layout` adjusts the subplot spacing, not
the spacing of tick labels.

If you just want to prevent overlap in the static case, you can just set
the tick labels yourself, e.g. `plt.xticks([1, 2, 3])`. If you want
something automatic and dynamic, ...

I believe this is actually a pretty difficult problem to solve in the
general case. I've implemented a hacky attempt
here,
but it leaves out a lot of common use cases (e.g. subplots) and doesn't
account for spacing between the axes and figure.

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] subplot and image

2012-01-31 Thread Tony Yu
On Tue, Jan 31, 2012 at 12:56 PM, Petro Khoroshyy wrote:

> Hi all
> I try to use matplotlib ti anotate some pictures.
> I wanted to combine two pictures into one using subplot. But apparently
> subplot does not work with images. How can I do it?
> Thanks
>
> P.S. Here is the source:
> import pylab
> import numpy
> import numpy as np
> import matplotlib.pyplot as plt
> from matplotlib import rcParams
> golden_mean = (numpy.sqrt(5)-1.0)/2.0 # Aesthetic ratio
> fig_width = 5.6  # width in inches
> fig_height = fig_width*golden_mean  # height in inches
> fig_size =  [fig_width,fig_height]
> rcParams['figure.figsize']=fig_width, fig_width
> rcParams['figure.dpi']=300
> rcParams['mathtext.default']='regular'
> rcParams['xtick.labelsize']=8
> rcParams['ytick.labelsize']=8
> pylab.rc('font', family='serif')
> pylab.rc('font', serif='Times New Roman')
> pylab.rc('text', usetex='false')
> pyp=mpimg.imread('/home/petro/mydoc/thesis/ready_pictures/pyp.jpg')
> fig=pylab.figure(facecolor="white")
> fig.subplots_adjust(top=0.95)
> fig.subplots_adjust(bottom=0.05)
> fig.subplots_adjust(left=0.05)
> fig.subplots_adjust(right=0.95)
> ax_left=fig.add_subplot(121)
> ax_left = pylab.axes(frameon=False)
> ax_left.set_axis_off()
> ax_left.imshow(pyp, origin='lower')
> plt.text(821, 707, r'$\beta _1$', {'color' : 'k', 'fontsize' : 12})
> pylab.savefig("pylab_pyp.png")
>
> --
> Petro.
>
>
Hi Petro,

I think the problem is that you create a subplot (...`add_subplot`...) and
then override it (...`pylab.axes`...). Remove the call to axes and you
should be set.

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to make a colored bar chart with named items and values shown above each bar?

2012-02-07 Thread Tony Yu
On Tue, Feb 7, 2012 at 1:01 PM, Martin Mokrejs
wrote:

> Hi,
>  I would like to create a bar chart like the attached example but with the
> addition
> that each bar would have a different color. I tried to learn this from the
> examples
> on matplotlib web but still do not see a close example for that. ;-)
> many thanks,
> Martin
>
>

Here's an example that does what you want (I think). There may be a better
way of setting the colors of the bars, but I don't use bar plots very often.

Hope that helps,
-Tony


import numpy as np
import matplotlib.pyplot as plt

colorcycle = ['red',
  'steelblue',
  'gold',
  'darkorchid',
  'yellowgreen',
  'darkorange',
  'silver',
  'darkturquoise',
  'hotpink',
  'mediumblue']


yy = np.random.uniform(5, 200, size=10).astype(int)
xx = range(len(yy))
width = 0.5
bars = plt.bar(xx, yy, width=width)

# add bar labels
for x, y in zip(xx, yy):
plt.text(x + 0.5*width, y, str(y), ha='center', va='bottom')

# change color of bars
for b, c in zip(bars, colorcycle):
b.set_color(c)

plt.show()
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] use the github version on a linux box

2012-02-08 Thread Tony Yu
On Wed, Feb 8, 2012 at 12:58 PM, Chris  wrote:

> This time the error is:
>
> fatal: Not a git repository (or any of the parent directories): .git
>
> I guess that I have not be able to establish a local git tree since the
> command
>
> git clone [email protected]:matplotlib/matplotlib.git matplotlib.git
>
> did not go through.
>
> - Chris
>
>
I don't think you want the ".git" at the very end of the clone command.
That just tells get where (i.e. new directory) to put the repo.

-Tony


> On Wed, Feb 8, 2012 at 9:48 AM, John Hunter  wrote:
> >
> >
> > On Wed, Feb 8, 2012 at 11:39 AM, Chris  wrote:
> >>
> >> Thanks John.  Since I already have a running copy of mpl, I skipped to
> >> the git clone step, but get this error:
> >>
> >> Permission denied (publickey).
> >> fatal: The remote end hung up unexpectedly
> >>
> >> I'm a complete noob on git, so please bear with me.
> >
> >
> >
> > I think I should have pointed you to the read only address.  Try this:
> >
> >
> >  git pull git://github.com/mdboom/matplotlib.git pixel_marker
> >
> > JDH
> >
>
>
> --
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] use the github version on a linux box

2012-02-08 Thread Tony Yu
On Wed, Feb 8, 2012 at 1:20 PM, Chris  wrote:

> New error at `git checkout -b mdboom-pixel_marker v1.1.x':
>
> fatal: git checkout: updating paths is incompatible with switching
> branches.
> Did you intend to checkout 'v1.1.x' which can not be resolved as commit?
>
> - Chris
>

That looks like something I've done before without issue. Maybe you're on
an older version of git. In any case, you can break this up into two steps

# change to maintenance branch
git checkout v1.1.x

# create new branch based on current checkout
git checkout -b mdboom-pixel_marker


Then continue as John instructed.

-Tony




>
> On Wed, Feb 8, 2012 at 10:13 AM, John Hunter  wrote:
> >
> >
> > On Wed, Feb 8, 2012 at 12:06 PM, Tony Yu  wrote:
> >
> >>> git clone [email protected]:matplotlib/matplotlib.git matplotlib.git
> >>>
> >>> did not go through.
> >>>
> >>> - Chris
> >>>
> >>
> >> I don't think you want the ".git" at the very end of the clone command.
> >> That just tells get where (i.e. new directory) to put the repo.
> >>
> >
> > I don't think that is the problem.  I just add the .git extension because
> > the default is to check out a directory called "matplotlib" which if it
> is
> > located in the path you are running or testing from, will confuse the
> > import.  So I just add some extension so python won't confuse the mpl src
> > dir ("matplotlib.git") with the mpl package ("matplotlib").
>
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot as individual "colorbars"

2012-02-14 Thread Tony Yu
On Tue, Feb 14, 2012 at 9:48 AM, Olе Streicher wrote:

> Hi list,
>
> I have a list of 48 individual data sets (lambda,y) which I want to plot in
> the following diagram:
>
> lambda
> ^
> |
> |
> |
> |
> +--->
>  1 2 3 4 5 6 .. Dataset #
>
> The "y" values should be color coded here, in a similar fashion as it is
> done in a color bar (f.e. that I can interpolate between data points).
>
> Practically, I want to have 48 vertical color bars here, all with the
> same scaling. From the documentation, I could not find out how to do
> this; and also I could not find a good example for this.
>
> Could anyone help me here?
>
> Best
>
> Ole
>
>
>
Does the following do what you need?

#
import numpy as np
import matplotlib.pyplot as plt

width = 0.5
height = 10

for x in np.arange(11):
strip = np.random.random(size=(50, 1))
plt.imshow(strip, extent=(x-width/2, x+width/2, 0, height))

plt.xlim(-width, x+width)

plt.show()
#

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot as individual "colorbars"

2012-02-14 Thread Tony Yu
On Tue, Feb 14, 2012 at 10:33 AM, Olе Streicher wrote:

> Tony Yu  writes:
> > Does the following do what you need?
> >
> > #
> > import numpy as np
> > import matplotlib.pyplot as plt
> >
> > width = 0.5
> > height = 10
> >
> > for x in np.arange(11):
> > strip = np.random.random(size=(50, 1))
> > plt.imshow(strip, extent=(x-width/2, x+width/2, 0, height))
> >
> > plt.xlim(-width, x+width)
> >
> > plt.show()
> > #
>
> Not completely since it requires an equally spaced "strip". I have two
> vectors (one for the vertical axis, one for the data).
>
> Best regards
>
> Ole
>
>
I'm not sure what you mean by equally spaced strip. If you need to scale
the height, you can just calculate it as from the length of the strip. If
you mean the placement of the strips, you can substitue the x values above
with your data instead of the `arange` call---you'd have to appropriately
scale `width` so that matches your x-spacing.

-Tony
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Selecting a color from a given color map.

2012-02-16 Thread Tony Yu
On Thu, Feb 16, 2012 at 4:14 PM, Daniel Welling wrote:

> Greetings.
>
> I have a series of lines that I would like to plot on the same axis,
> but I would like to set the color of each such that the range of
> colors used progresses through a given color map (e.g. the default Jet
> map.)  For example, if I have 7 lines, the first would use the first
> most color from the Jet color map (blue.)  The next line would use the
> color that is 1/7 the way up the map, e.g. green or so.  This would
> continue until the last line was red.
>
> How would I go about doing this (that is, loading a color map and
> pulling a specific color from it that could be handed to plot as an
> rgba tuple)?
>
> Thanks!
> -dw
>
>
Hi Daniel,

You can just pass values to a colormap. If those values are evenly spaced
between 0 and 1, you'll get the result you desire. Example:

#~

import numpy as np
import matplotlib.pyplot as plt

n_lines = 10
x = np.linspace(0, 10)

phase_shift = np.linspace(0, np.pi, n_lines)
color_idx = np.linspace(0, 1, n_lines)
for i, shift in zip(color_idx, phase_shift):
plt.plot(x, np.sin(x - shift), color=plt.cm.jet(i))

plt.show()

#~

Coincidentally, this past weekend, I started wrapping up random code like
this into a utility package. See `cycle_cmap` in this package:
https://github.com/tonysyu/mpltools/blob/master/mpltools/color.py. The
package is still in the early stages, and function names could easily
change, so use with caution.

Best,
-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot as individual "colorbars"

2012-02-18 Thread Tony Yu
On Tue, Feb 14, 2012 at 12:49 PM, Olе Streicher wrote:

> Jerzy Karczmarczuk
>  writes:
> > Could you provide a /working/ example with the geometry you really want?
> > I believe I thought more or less about it as Tony Yu did. If it is
> > wrong, be more precise, please.
>
> I have a data set that looks like this:
>
> mydata = numpy.copy([
>
> # lambda,  data
>
> # First data row
>  [[5002., 0.5],
>  [5200., 0.34],
>  [5251., -1.2],
> #  ...
>  [8997., 2.4]],
>
> # second data row
>  [[5002., 0.72],
>  [5251., 0.9],
> #  ...
>  [8997.,  0.1]],
>
> # other data rows to follow
> #  ...
>  ])
>
> where I want to put the first column (lambda) on the Y axis, which each
> data row as one colorbar (like in your code), and the data as the color
> of that data point -- interpolated vertically.
>
> Best regards
>
> Ole
>
>
OK, I see now.

Unfortunately, this makes it quite a bit more complex, but it's still
doable. Part of the complexity arises because of (what I believe to be) a
quirk in NonUniformImage: You can pass an extent argument, but this only
rescales the data---it doesn't clip the data. You have to manually clip the
borders of each bar.

Here's an example:

#---
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import NonUniformImage

width = 0.5
height = 10

ax = plt.gca()

for x0 in np.arange(11):
y = np.sort(np.random.uniform(high=height, size=10))
z = np.random.random(size=(10, 1))
# Note NonUniformImage fails with single column; double up data
z = np.repeat(z, 2, axis=1)
x = [x0, x0]

extent = (x0-width/2., x0+width/2, y[0], y[-1])
im = NonUniformImage(ax, interpolation='bilinear', extent=extent)
im.set_data(x, y, z)

# clip image
x_left = extent[0]
xm = [x_left, x_left + width, x_left + width, x_left]
ym = [0, 0, height, height]
mask, = ax.fill(xm, ym, facecolor='none', edgecolor='none')
im.set_clip_path(mask)

ax.images.append(im)

ax.set_xlim(-width, x0+width)

plt.show()
#---

HTH,
-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Fwd: Matplotlib gallery

2012-02-23 Thread Tony Yu
On Thu, Feb 23, 2012 at 11:32 AM,  wrote:

> I will never get use to reply-all
>
> -- Forwarded message --
> From:  
> Date: Thu, Feb 23, 2012 at 11:31 AM
> Subject: Re: [Matplotlib-users] Matplotlib gallery
> To: Nicolas Rougier 
>
>
> On Thu, Feb 23, 2012 at 11:24 AM, Nicolas Rougier
>  wrote:
> >
> >
> > I agree, but the current matplotlib gallery is rather clueless about
> what the examples are related to until you click an image. I'm personally
> using the gallery by looking at an example that match what I've in mind
> most closely and then look at the code. But you're right, some structure(s)
> would definitely help.
> >
> > Here is an example of a well structured gallery:
> http://www.gigawiz.com/aagraphs.html.
> >
> > The first-level structure is organized at:
> >
> > Specialized Scientific Graphing
> > Scatter Graphs
> > Contour Charts (2-D, 3-D, and Ternary)
> > Heatmaps
> > Voronoi Diagram
> > Waterfall Charts
> > Bubble Charts
> > Spider Charts
> > Polar Charts
> > Column and Bar Charts
> > Area Charts
> > Line Charts
> > Combination Charts (Column-Line, Bar-Line, Area-Line)
> > Diagrams of Multiple, Independent Value-Axes Column, Bar or Area Graphs
> > High-Low, (Open)-High-Low-Close, and Range Charts
> > Pie Charts and X-Y Scatter Pie
> > Vector Charts
> > Statistical Charts
> >
> >
> > Maybe we can find/agree on similar structure(s)/sub-structure(s) and
> adapt it to the current gallery ?
>
> An advantage of the current all in one page gallery is that it is
> easier to find a recipe when I just look for individual plot elements,
> when I have not much idea what it might be called and just some idea
> what it should look like.
>
> That's different from looking for plots with a specific usage or content.
>
> Josef
>
>
You could still have a one-page gallery with plots separated into
subheadings (and a table of contents at the top which allows you to jump to
subheadings). This alone would greatly improve navigation in the gallery.
The list of headings is great, by the way.

-Tony


>
> >
> >
> > Nicolas
> >
> >
> >
> > On Feb 23, 2012, at 16:59 , Jerzy Karczmarczuk wrote:
> >
> >>  Nicolas Rougier :
> >>> I've seen the discussion around the re-organization of the matplotlib
> gallery.
> >>> If that might help, here is a link to a small gallery I made.
> >>>
> >>> The overall organization is simply based on subdirectories so maybe it
> could be a (temporary) solution for the matplotlib gallery (just matter of
> moving examples in the right subdirectory).
> >> THANKS, Nicolas.
> >>
> >> This is a nice initiative, but I believe that in the context of a
> >> presentation of some software, this is not the way I would have chosen.
> >> Why people look-up /such/ galleries? Why I do it myself? What are the
> >> needs of my students (about 20 - 30 guys who work with matplotlib week
> >> after wek)?
> >>
> >> Often because I want to find a concrete program, which answers a
> >> concrete question : how to implement timed animations. How to make
> >> multiple plots. How to insert a figure in a GUI with widgets, how to
> >> distort an image matrix, etc. etc. So a gallery should contains infos
> >> about what the hell the example XYZ is about, what does it show, where
> >> is the *concrete* documentation page with the description of the tools
> >> used, etc.
> >>
> >> The order of examples should be rational, and as ALWAYS some cross-links
> >> would be useful.
> >> Program-sources without comments are not so useful...
> >>
> >> ==
> >>
> >> But I believe that this is just a start, and I am aware that to
> >> criticize is easier than to do something. (Je suis un grognon né,
> >> Nicolas, désolé...). So please, continue, my heart is with you!
> >>
> >>
> >> Jerzy Karczmarczuk
> >> Caen, France.
> >>
> >>
> >>
> --
> >> Virtualization & Cloud Management Using Capacity Planning
> >> Cloud computing makes use of virtualization - but cloud computing
> >> also focuses on allowing computing to be delivered as a service.
> >> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> >> ___
> >> Matplotlib-users mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
> >
> --
> > Virtualization & Cloud Management Using Capacity Planning
> > Cloud computing makes use of virtualization - but cloud computing
> > also focuses on allowing computing to be delivered as a service.
> > http://www.accelacomm.com/jaw/sfnl/114/51521223/
> > ___
> > Matplotlib-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
> --
> Virtualization & Cloud Management Using 

Re: [Matplotlib-users] draw_event

2012-02-28 Thread Tony Yu
On Tue, Feb 28, 2012 at 4:05 PM, Antoine Sirinelli  wrote:

> Hi,
>
> I have been using the event "draw_event" for a while with the old
> matplotlib 0.8. I have tested my program with newer versions but it seems
> the function connected to "draw_event" is never called.
>
> You can find an example of this there: https://gist.github.com/1901504
>
> With an old version the image color scale is rescaled when you zoom in.
> With matplotlib 1.x, no change is made on on the color scale.
>
> Have I missed something?
>
> Thanks in advance for your help.
>
> Antoine
>

Hey Antoine,

I'm not sure what changed in the mean time, but the problem is that the
instances of `az_imshow` aren't saved to anything (e.g. you should write
`implot2 = az_imshow(data, aspect='auto')`). I *think* what happens is that
you don't have any references to the object so it gets garbage-collected
and the events you create disappear. That's my made-up explanation.

-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Arrow with a dashed line

2012-03-11 Thread Tony Yu
Is it possible to draw an arrow with a dashed line?

I tried using a fancy arrow patch and set the linestyle:

#~~~
import matplotlib.pyplot as plt

fix, ax = plt.subplots()
ax.set_xlim((-1,5))
ax.set_ylim((-5,3))

ax.annotate('simple', xy=(2., -1),  xycoords='data',
xytext=(100, 60), textcoords='offset points',
size=20,
arrowprops=dict(arrowstyle="simple",
fc="0.6", ec="none", linestyle='dashed',
connectionstyle="arc3,rad=0.3"),
)
plt.show()
#~~~

But the linestyle argument just gets ignored.

Is there a way to grab the connection path object and then change that to a
dashed line? Actually, I'm not even sure it's possible to set a linestyle
for a Path (since dashed lines are normally Line2D). Suggestions?

Thanks,
-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Arrow with a dashed line

2012-03-12 Thread Tony Yu
On Sun, Mar 11, 2012 at 2:13 PM, Tony Yu  wrote:

> Is it possible to draw an arrow with a dashed line?
>
> I tried using a fancy arrow patch and set the linestyle:
>
> #~~~
> import matplotlib.pyplot as plt
>
> fix, ax = plt.subplots()
> ax.set_xlim((-1,5))
> ax.set_ylim((-5,3))
>
> ax.annotate('simple', xy=(2., -1),  xycoords='data',
> xytext=(100, 60), textcoords='offset points',
> size=20,
> arrowprops=dict(arrowstyle="simple",
> fc="0.6", ec="none", linestyle='dashed',
> connectionstyle="arc3,rad=0.3"),
> )
> plt.show()
> #~~~
>
> But the linestyle argument just gets ignored.
>
> Is there a way to grab the connection path object and then change that to
> a dashed line? Actually, I'm not even sure it's possible to set a linestyle
> for a Path (since dashed lines are normally Line2D). Suggestions?
>
> Thanks,
> -Tony
>


Nevermind: I though arrowstyle='simple' and arrowstyle='-|>' were the same
thing, but apparently not (I guess one draws the line as a patch, and the
other as a line). So the following works as expected:

#
import matplotlib.pyplot as plt

fix, ax = plt.subplots()
ax.set_xlim((-1,5))
ax.set_ylim((-5,3))

ax.annotate('simple', xy=(2., -1),  xycoords='data',
xytext=(100, 60), textcoords='offset points',
size=20,
arrowprops=dict(arrowstyle="-|>",
fc="k", ec="k", linestyle='dashed',
connectionstyle="arc3,rad=0.3"),
)
plt.show()
#~~~
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to draw an arrow

2012-03-14 Thread Tony Yu
On Wed, Mar 14, 2012 at 6:02 AM, kususe  wrote:

>
> Hi folks,
> I've to draw an arrow.
> I used Arrow() function:
>
> pa.Arrow(0, 0, x, y, width=1.0)
>
> where I imported
>
> matplotlib.patches as pa
>
> Now, how to use plot() function di display the figure?
>
> Tanks in advance,
> K.
> --
> View this message in context:
> http://old.nabble.com/How-to-draw-an-arrow-tp33500720p33500720.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
Hi,

You need to add the patch to the current axes. For example,

#~~~
import matplotlib.pyplot as plt
from matplotlib import patches
arr = patches.Arrow(0,0,1,1)
ax = plt.gca()
ax.add_patch(arr)
plt.show()
#~~~

When you create a Matplotlib artist (here a `Patch` artist) with pyplot
(e.g. `plt.plot` creates a Line2D instance), pyplot takes care of matching
artist with axes. Artists themselves don't know anything about where you're
plotting, so you have to tell it where to go.

-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to remove x axis in a subplotted graph

2012-03-14 Thread Tony Yu
On Wed, Mar 14, 2012 at 5:44 AM, kususe  wrote:

>
> Hi folks,
> I have a graph got using the subplot command.
> I'd like to remove all ticks in X axis in all of graph.
>
> I used: plt.setp(plt.gca(),'XtickLabel',[])
>
> but I get that:
>
> File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 1169, in
> setp
>func = getattr(o,funcName)
> AttributeError: 'AxesSubplot' object has no attribute 'set_xticklabel'
>
> Suggestions?
> Thanks in advance
> K
>
>
You're missing an "s"; i.e. "xticklabels". Also, the more conventional
pattern is to call the axes method, i.e.:

>>> ax = plt.gca()
>>> ax.set_xticklabels([])

or, if want to remove both labels and the tick-lines

>>> ax.set_xticks([])

Best,
-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib website problems?

2012-03-14 Thread Tony Yu
On Wed, Mar 14, 2012 at 9:58 AM, Jonathan Slavin wrote:

> Hi,
>
> Recently on several occasions I have gotten the response "Too many
> requests, please try again later." when trying to go to a matplotlib
> webpage.  Have others experienced this also?  Is this a problem with
> sourceforge?  I'm wondering what could be done about this.  It's very
> annoying when, for example, you want to see the source code for some
> useful example and you have to try back several times to get to the
> page.
>
> Jon
> --
> __
>
>
No insights here, just confirmation: I've also gotten this error message a
few times over the last few weeks.

-Tony
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to remove x axis in a subplotted graph

2012-03-14 Thread Tony Yu
On Wed, Mar 14, 2012 at 1:41 PM, kususe  wrote:

>
> Thanks, it works.
> But if the graph is just one in a figure.
>
> I created various graph and I wanna remove all ticks in all of X axis.
> I coded:
>
>plt.subplot(3,1,1)
>p1, = plt.plot(self.data0,self.data1)
>.
>plt.subplot(3,1,2)
>p2, = plt.plot(self.data0,self.data2)
>.
>plt.subplot(3,1,3)
>p3, = plt.plot(self.data0,self.data4)
>.
>
> how can I work the problem out?
>

I would do the following (`subplots` requires mpl 1.0, I think):

fig, axes = plt.subplots(ncols=3)
ax1, ax2, ax3 = axes
ax1.plot(x, y1)
...
ax2.plot(x, y2)
...
ax3.plot(x, y3)
...
for ax in axes:\
ax.set_xticks([])
    ...


Cheers,
-Tony

Thanks in advance
> K.
>
>
> Tony Yu-3 wrote:
> >
> > On Wed, Mar 14, 2012 at 5:44 AM, kususe  wrote:
> >
> >>
> >> Hi folks,
> >> I have a graph got using the subplot command.
> >> I'd like to remove all ticks in X axis in all of graph.
> >>
> >> I used: plt.setp(plt.gca(),'XtickLabel',[])
> >>
> >> but I get that:
> >>
> >> File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 1169, in
> >> setp
> >>func = getattr(o,funcName)
> >> AttributeError: 'AxesSubplot' object has no attribute 'set_xticklabel'
> >>
> >> Suggestions?
> >> Thanks in advance
> >> K
> >>
> >>
> > You're missing an "s"; i.e. "xticklabels". Also, the more conventional
> > pattern is to call the axes method, i.e.:
> >
> > >>> ax = plt.gca()
> > >>> ax.set_xticklabels([])
> >
> > or, if want to remove both labels and the tick-lines
> >
> > >>> ax.set_xticks([])
> >
> > Best,
> > -Tony
> >
> >
> --
> > Virtualization & Cloud Management Using Capacity Planning
> > Cloud computing makes use of virtualization - but cloud computing
> > also focuses on allowing computing to be delivered as a service.
> > http://www.accelacomm.com/jaw/sfnl/114/51521223/
> > ___
> > Matplotlib-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> >
> >
> --
> View this message in context:
> http://old.nabble.com/How-to-remove-x-axis-in-a-subplotted-graph-tp33500598p33504036.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
>
> --
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to remove x axis in a subplotted graph

2012-03-14 Thread Tony Yu
On Wed, Mar 14, 2012 at 2:38 PM, kususe  wrote:

>
> I got an error using the first subplot function because I have to specify 3
> parameters.
> If i do it, I get that "AxesSubplot' object is not iterable"
> I coded using 3 subplot functions, getting the same error.
>
> Thanks
> K.
>
>
Note that I wrote `subplots` with an "s", which is a different command than
`subplot`. (You're really having problems with "s"s today :)

BTW, would you mind interleaving or bottom-posting
replies<http://en.wikipedia.org/wiki/Posting_style#Placement_of_replies>.
It's a bit easier to follow the conversation that way.

-Tony


>
> Tony Yu-3 wrote:
> >
> > On Wed, Mar 14, 2012 at 1:41 PM, kususe  wrote:
> >
> >>
> >> Thanks, it works.
> >> But if the graph is just one in a figure.
> >>
> >> I created various graph and I wanna remove all ticks in all of X axis.
> >> I coded:
> >>
> >>plt.subplot(3,1,1)
> >>p1, = plt.plot(self.data0,self.data1)
> >>.
> >>plt.subplot(3,1,2)
> >>p2, = plt.plot(self.data0,self.data2)
> >>.
> >>plt.subplot(3,1,3)
> >>p3, = plt.plot(self.data0,self.data4)
> >>.
> >>
> >> how can I work the problem out?
> >>
> >
> > I would do the following (`subplots` requires mpl 1.0, I think):
> >
> > fig, axes = plt.subplots(ncols=3)
> > ax1, ax2, ax3 = axes
> > ax1.plot(x, y1)
> > ...
> > ax2.plot(x, y2)
> > ...
> > ax3.plot(x, y3)
> > ...
> > for ax in axes:\
> > ax.set_xticks([])
> > ...
> >
> >
> > Cheers,
> > -Tony
> >
> > Thanks in advance
> >> K.
> >>
> >>
> >> Tony Yu-3 wrote:
> >> >
> >> > On Wed, Mar 14, 2012 at 5:44 AM, kususe  wrote:
> >> >
> >> >>
> >> >> Hi folks,
> >> >> I have a graph got using the subplot command.
> >> >> I'd like to remove all ticks in X axis in all of graph.
> >> >>
> >> >> I used: plt.setp(plt.gca(),'XtickLabel',[])
> >> >>
> >> >> but I get that:
> >> >>
> >> >> File "/usr/lib/pymodules/python2.6/matplotlib/artist.py", line 1169,
> >> in
> >> >> setp
> >> >>func = getattr(o,funcName)
> >> >> AttributeError: 'AxesSubplot' object has no attribute
> 'set_xticklabel'
> >> >>
> >> >> Suggestions?
> >> >> Thanks in advance
> >> >> K
> >> >>
> >> >>
> >> > You're missing an "s"; i.e. "xticklabels". Also, the more conventional
> >> > pattern is to call the axes method, i.e.:
> >> >
> >> > >>> ax = plt.gca()
> >> > >>> ax.set_xticklabels([])
> >> >
> >> > or, if want to remove both labels and the tick-lines
> >> >
> >> > >>> ax.set_xticks([])
> >> >
> >> > Best,
> >> > -Tony
> >> >
> >> >
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] How to remove the black border in a Matplotlib figure

2012-03-15 Thread Tony Yu
On Thu, Mar 15, 2012 at 6:01 AM, kususe  wrote:

>
> Hi folks,
> I'd like to remove the black border which is created when I save the image,
> letting just the white background and the graph.
> Is there a solution??
> Thanks,
> K.
> --


Matplotlib provides a function that *almost* does this: `plt.axis('off')`
or `ax.set_axis_off()`, but these functions clear the white background as
well (along with the ticks, spines, and axis labels).

The following snippet clears only the spines and ticks:

ax.xaxis.set_ticks([])
ax.yaxis.set_ticks([])
for spine in ax.spines.itervalues():
spine.set_visible(False)

I've wrapped this up into a utility function:
https://github.com/tonysyu/mpltools/blob/master/mpltools/layout.py

-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Why are bars, errorbars... clipped

2012-03-18 Thread Tony Yu
On Sun, Mar 18, 2012 at 9:14 AM, klo uo  wrote:

> On Sun, Mar 18, 2012 at 1:50 PM, Angus McMorland wrote:
>
>>
>> For inline ipython, you want to switch to the object-oriented use of
>> pylab. Something like this should work with xlim.
>>
>> a = [0.1, 0.2, 0.1]
>> fig = plt.figure()
>> ax = fig.add_subplot(111)
>> ax.errorbar(arange(3), a, yerr=a-sum(a)/len(a), fmt='ro')
>> ax.set_xlim(-.5,2.5)
>> ax.show()
>>
>> I'm not aware of automatic settings for padding, but with this
>> set_xlim, it's easy enough to roll your own using the data limits.
>>
>>
> OK, thanks
>
> It's not very elegant (assuming pylab freedom) but I take it as only way
> to correct clipping example (or differently put - to use custom range for
> axis)
>
>
You can roll out a utility function that can automatically adjust the
limits with some specified padding (i.e. the function doesn't calculate the
marker size, but you can just give it sufficient padding).

Here's an example where you specify a padding passed on the axes size (0.05
is 5% of axes height/width):

#
import numpy as np
import matplotlib.pyplot as plt

def pad_limits(pad_frac=0.05, ax=None):
ax = ax if ax is not None else plt.gca()
ax.set_xlim(_calc_limits(ax.xaxis, pad_frac))
ax.set_ylim(_calc_limits(ax.yaxis, pad_frac))

def _calc_limits(axis, frac):
limits = axis.get_data_interval()
mag = np.diff(limits)[0]
pad = np.array([-mag*frac, mag*frac])
return limits + pad

a = np.array([0.1, 0.2, 0.1])

plt.errorbar(np.arange(3), a, yerr=a-sum(a)/len(a), fmt='ro')
pad_limits()

plt.show()
#

I've put this is my personal mpl toolkit with the added ability of handling
log scales:
https://github.com/tonysyu/mpltools/blob/master/mpltools/layout.py#L80

Best,
-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Why are bars, errorbars... clipped

2012-03-18 Thread Tony Yu
On Sun, Mar 18, 2012 at 11:08 AM, Benjamin Root  wrote:

>
>
> On Sunday, March 18, 2012, Tony Yu  wrote:
> >
> >
> > On Sun, Mar 18, 2012 at 9:14 AM, klo uo  wrote:
> >>
> >> On Sun, Mar 18, 2012 at 1:50 PM, Angus McMorland 
> wrote:
> >>>
> >>> For inline ipython, you want to switch to the object-oriented use of
> >>> pylab. Something like this should work with xlim.
> >>>
> >>> a = [0.1, 0.2, 0.1]
> >>> fig = plt.figure()
> >>> ax = fig.add_subplot(111)
> >>> ax.errorbar(arange(3), a, yerr=a-sum(a)/len(a), fmt='ro')
> >>> ax.set_xlim(-.5,2.5)
> >>> ax.show()
> >>>
> >>> I'm not aware of automatic settings for padding, but with this
> >>> set_xlim, it's easy enough to roll your own using the data limits.
> >>>
> >>
> >> OK, thanks
> >>
> >> It's not very elegant (assuming pylab freedom) but I take it as only
> way to correct clipping example (or differently put - to use custom range
> for axis)
> >>
> >
> > You can roll out a utility function that can automatically adjust the
> limits with some specified padding (i.e. the function doesn't calculate the
> marker size, but you can just give it sufficient padding).
> > Here's an example where you specify a padding passed on the axes size
> (0.05 is 5% of axes height/width):
> > #
> > import numpy as np
> > import matplotlib.pyplot as plt
> > def pad_limits(pad_frac=0.05, ax=None):
> > ax = ax if ax is not None else plt.gca()
> > ax.set_xlim(_calc_limits(ax.xaxis, pad_frac))
> > ax.set_ylim(_calc_limits(ax.yaxis, pad_frac))
> > def _calc_limits(axis, frac):
> > limits = axis.get_data_interval()
> > mag = np.diff(limits)[0]
> > pad = np.array([-mag*frac, mag*frac])
> > return limits + pad
> > a = np.array([0.1, 0.2, 0.1])
> > plt.errorbar(np.arange(3), a, yerr=a-sum(a)/len(a), fmt='ro')
> > pad_limits()
> > plt.show()
> > #
> > I've put this is my personal mpl toolkit with the added ability of
> handling log scales:
> > https://github.com/tonysyu/mpltools/blob/master/mpltools/layout.py#L80
> > Best,
> > -Tony
> >
>
>
> Uhm, don't we already have padx and pady kwargs for various limits
> functions?  I know scatter and plot respects them.
>
> Ben Root


Oh, I didn't know anything about them. ... and where exactly? I can't seem
to find them (I looked in `ax.autoscale`, `ax.autoscale_view`, and
`plt.xlim`).

-Tony

(Sorry for the duplicate, Ben. I forgot to reply all)
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] sample to contribute to mpl gallery

2012-03-20 Thread Tony Yu
On Tue, Mar 20, 2012 at 4:10 PM, Daniel Hyams  wrote:

> There was a request a while back to create plots that are more
> application-oriented for the matplotlib gallery, so I'd like to submit this
> one for inclusion.  I tried to spruce it up a bit to show what MPL can do,
> and I'm sure that the folks here can improve upon it.  But at any rate,
> this is a good first iteration I think.
>
> I'm also going to try to replace the plot at wikipedia (for the Moody
> diagram) with this one.  The one at wikipedia is not quite correct in the
> way friction factors are computed, and a nice side effect is that mpl gets
> some exposure there as well (although there are probably dozens of mpl
> plots already there, but I don't know how to find them).
>
> The below is meant as constructive criticism; I certainly am committed to
> using matplotlib and offering patches here and there as I can; I would love
> to see wider adoption of it.  I also concede that in the below items, I
> might have missed something obvious.  I'm trying to approach this as a user
> who was just introduced to matplotlib, and had to create the plot that is
> attached.
>
> 1) The table mechanism, while very nice and useful, could use some
> improvement; it should be easier to specify alignment for the table cells,
> and individual fonts for each cell.
> 2) drawing the arrows was much harder than it needs to be.  Better
> defaults for arrowhead sizes would help a lot (instead of them being
> hardcoded to certain numbers, have the defaults be fungible based on how
> long the arrow is in pixel space), and I had to resort to using the
> annotate() function to draw them, after spending over an hour trying to use
> plt.arrow().  plt.arrow() had some problems drawing arrowheads on log-log
> plots, and well as not supporting a double-ended arrow.
> 3) drawing the shading using polygons was great and easy.
> 4) the title by default is placed too close to the top
> 5) the plot axis labels were clipped by default; had to pull the axis
> limits in (I know, this is a longstanding thing, but a new user would
> wrinkle their nose)
>
> All in all, the plot took a lot longer to make than I had anticipated;
> mainly due to some fussing with the issues above until I found something
> that worked.
>
> Hope that you find the sample useful.
>
> --
> Daniel Hyams
> [email protected]
>

I'm not one of the mpl-developers, so I can't speak about the likelihood of
inclusion, but I do think it's a great plot (esp. since my background is in
fluid mechanics). I think it'd be a great example to have, especially if
the gallery gets split up into different
categories.
(Personally,
I think it would be nice to have a category for complex, application-style
examples, and multiple categories for simplified-versions of most of the
current examples).

I agree with most of your points, but I don't have much to add on anything
except for #2: Drawing arrows has been painful for me as well. If I find
the time, I plan on putting together a PR which draws arrows using a
FancyArrowPatch and a Line2D object. Although, `annotate` works great for
it's designed purpose, it can be cumbersome for drawing simple arrows.

-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] why does transform=None cause a patch not to be shown?

2012-03-25 Thread Tony Yu
On Thu, Mar 22, 2012 at 1:43 AM, C M  wrote:

> For the following code, if I remove the transform=None a green patch is
> shown.  If it is in, it is not shown.  I would think that transform=None
> should have no effect.  Why is this?
>

This is a weird one: When you set the transform, the artist notices (sets
the `_transformSet` flag) and remembers that you set it. If the axes sees
that you've set the artist's transform, it won't override the artist's
transformwith
the data transform (which is what properly scales your patch to the
data coordinates).

Best,
-Tony


>
> Thanks,
> Che
>
>
> import matplotlib.pyplot as plt
> import matplotlib.patches as patches
> from matplotlib.path import Path
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> start = 0.2
> stop = .6
>
> verts = [
> (start, .2), # left, bottom
> (start, .4), # left, top
> (stop, .4), # right, top
> (stop, .2), # right, bottom
> (0., 0.), # ignored
> ]
> codes = [Path.MOVETO,
>  Path.LINETO,
>  Path.LINETO,
>  Path.LINETO,
>  Path.CLOSEPOLY,
>  ]
>
> path = Path(verts, codes)
>
> patch = patches.PathPatch(path, facecolor='g',
>   lw=1, edgecolor='grey',transform=None )
>
> ax.add_patch(patch)
>
> plt.show()
>
>
> --
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scatter plot with a specific size per point

2012-03-26 Thread Tony Yu
On Mon, Mar 26, 2012 at 8:26 AM, Matthieu Brucher <
[email protected]> wrote:

> Indeed, a little bit less simple, but the solution nonetheless.
>
> Thank you!
>
>
> 2012/3/26 Zachary Pincus 
>
>> > I'd like to display a scatter plot where the size for each element is
>> fixed. Currently, when I modify the size of the figure, the size of a
>> marker is fixed, and I would like it to be proportional to the window.
>> > I want this because the size of the marker indicates an extent, and I
>> would like it to confirm that the extents correctly cover the other points.
>>
>> If it's truly an extent, you might be better off drawing polygons of the
>> extent boundaries in the graph's coordinate system -- then things will
>> scale as you desire. This will require digging down a bit into the object
>> API -- make a new matplotlib.collections.PolyCollection (or
>> RegularPolyCollection), and add it to your axes with Axes.add_collection().
>>
>> Zach
>> -
>
>
I needed something similar a while back, and Jae-Joon Lee helped me find a
decent solution. Here're the results for square markers:

#~~~
import matplotlib.collections as collections
import matplotlib.transforms as transforms

class SquareCollection(collections.RegularPolyCollection):
"""Return a collection of squares."""

def __init__(self, **kwargs):
super(SquareCollection, self).__init__(4, rotation=np.pi/4.,
**kwargs)

def get_transform(self):
"""Return transform scaling circle areas to data space."""
ax = self.axes
pts2pixels = 72.0 / ax.figure.dpi
scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width
scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height
return transforms.Affine2D().scale(scale_x, scale_y)
#~~~

 Example 
use
.

Best,
-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] reverse colormap?

2012-03-29 Thread Tony Yu
On Thu, Mar 29, 2012 at 1:31 PM, Chao YUE  wrote:

> Dear all,
>
> here in cookbook it says "Ever wanted to reverse a colormap, or to
> desaturate one ? Here is a routine to apply a function to the look up table
> of a colormap: "
> http://www.scipy.org/Cookbook/Matplotlib/ColormapTransformations
>
> but I don't know how to use cmap_map function as in the link to reverse,
> for example, the cm.jet colormap?
>


If all you want is the reversed colormap, you can call `cm.jet_r` (all the
default colormaps have a `_r` version). From a *quick* look at the example
you link to, it seems that you can pass `lambda x: 1 - x` as the function
to `cmap_xmap`.

Cheers,
-Tony

(Chao: Sorry for the duplicate. Forgot to reply-all)


> thanks,
>
> Chao
> --
>
> ***
> Chao YUE
> Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
> UMR 1572 CEA-CNRS-UVSQ
> Batiment 712 - Pe 119
> 91191 GIF Sur YVETTE Cedex
> Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
>
> 
>
>
>
> --
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] padding axis limits automatically?

2012-03-30 Thread Tony Yu
On Fri, Mar 30, 2012 at 2:47 PM, Skipper Seabold wrote:

> There is probably a simple answer to this, but I don't see it. How can
> I pad the axis limits automatically? For instance, in the below
> example, the x axis limits are the data points and the y limit is
> close. I want to have a function that pads the axis limit at least, by
> say, 10% of the range of x past the last data point without having to
> take my x values and calculate some sensible x limit. Is this
> possible?
>
>
> import matplotlib.pyplot as plt
> fig = plt.figure()
> ax = fig.add_subplot(111)
> x = [1,2,3]
> y = [8125, 9754, 10855]
> ax.plot(x,y,marker='D',ms=12)
> plt.show()
>
>
A similar 
issuecame
up recently on the list:
http://old.nabble.com/Why-are-bars,-errorbars...-clipped-td33525497.html

I posted a snippet of
codethere.
Ben Root also mentioned `padx` and `pady` parameters, but I was not
able to find them.

Best,
-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] padding axis limits automatically?

2012-03-30 Thread Tony Yu
On Fri, Mar 30, 2012 at 4:40 PM, Eric Firing  wrote:

> On 03/30/2012 08:47 AM, Skipper Seabold wrote:
> > There is probably a simple answer to this, but I don't see it. How can
> > I pad the axis limits automatically? For instance, in the below
> > example, the x axis limits are the data points and the y limit is
> > close. I want to have a function that pads the axis limit at least, by
> > say, 10% of the range of x past the last data point without having to
> > take my x values and calculate some sensible x limit. Is this
> > possible?
>
> Does the margins() function or method do what you want?
>
>
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.margins
>
>
> http://matplotlib.sourceforge.net/api/axes_api.html?highlight=margins#matplotlib.axes.Axes.margins
>
> Eric
>
> Thanks for the tip, Eric. I'm continually surprised by all the useful
stuff that's nestled in the corners of matplotlib.

Hmm, it looks like `margins` doesn't support log scales, though. Maybe I'll
submit a PR on this later.

Best,
-Tony
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Copying a figure instance?

2012-03-31 Thread Tony Yu
On Fri, Mar 30, 2012 at 12:25 PM, eoj  wrote:

>
> Basically the problem is like this. I have a relatively expensive (time
> wise)
> figure to create, specifically a map with lots of detail in it. On top of
> that, I'm  making an inset set of axes to highlight some regions. I'm
> having
> to recreate the base of the map, which is static, every time I want to make
> an inset for a different region which is taking forever. What I want to do
> is something like this:
>
> fig = figure()
>
> #do stuff that makes the expensive figure
>
> for region in regions:
>fig2 = copy.copy(fig)
>ax2 = fig.add_axes([0.1, 0.15, 0.25, 0.25])
>ax2.fill(x1,y1)
>savefig(region_name)
>close()
>
>
>
> The problem is that the clf() clear figure function seems to clear the base
> of the map off, even if I try to make a copy of it inside a loop that is
> generating the insets. Also, close() seems to close fig and not fig2. Does
> this rambling make any sense, and if so, any suggestions?
>
>
If all your additions are confined to the inset axes, you can use
`fig.delaxes` to remove the axes from the figure (see example below). If
you want to save and restore, as you describe above, you should (in
principal) be able to do so with `canvas.copy_from_bbox` and
`canvas.restore_region`, but I couldn't get it to work (see bottom of the
animation cookbook ).

Cheers,
-Tony

# ~~~ example
import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.imshow(np.random.uniform(size=(10, 10)))

ax_inset = fig.add_axes([0.3, 0.3, 0.2, 0.2])
ax_inset.plot([0, 1])
plt.savefig('plot0')

fig.delaxes(ax_inset)
ax_inset = fig.add_axes([0.5, 0.5, 0.2, 0.2])
ax_inset.plot([1, 0])
plt.savefig('plot1')
# ~~~
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] [Bug] : yaxis presentation going wrong if ymin/ymax < .000x (x~ 5)

2012-04-23 Thread Tony Yu
On Mon, Apr 23, 2012 at 5:09 AM, jul tayon  wrote:

> Hello list
>
> matplotlib website says this mailing  is the prefered way to report
> bug, so here I am :
>
> System :
> python ; 2.7.2+
> matplotlib 1.1.0
> ubuntu TLS amd64
> matplotlib Backend : TkAgg
>
>
> How to reproduce (on my pf)
> Code Snippet :
>
> ##CODE
>
> import matplotlib
> import matplotlib.pyplot as p
> import random
> y = random.randint(0,1000)
> p.plot( [ int( y * ( 1 - 0.0006)) , y])
> p.show()
>
> ##ENDCODE
>
> Exected Result :
> https://github.com/jul/pypi-stat/blob/master/why.png
>
> Cause ?
>
> It stinks something like a rounding error on the float.
> If it also happens in Qt/Gtk backend it might be a matplotlib bug, if
> it is only in Tk then it is either a Tk or a TkAgg bug.
>
> Cheers,
> --
> Jul
>

Sorry, I'm not clear on what the bug is. Is the picture you link to the
*expected* result or the result from *executing* the code snippet. There
are some inconsistencies between the pic and the code (legend, time on
xaxis, 3 point in pic, title), so it's a bit unclear what you're referring
to.

If you're talking about the offset value added to the y-axis, it's actually
not a bug; it's a feature (usually that's a joke, but in this case, I'm
serious).

This feature is useful when you have large numbers that vary over small
ranges. Maybe it's not so bad in your example, but for larger numbers with
smaller ranges (see code snippet below), it's quite helpful. I thought
there was an rc parameter to tweak the value for using offsets, but I can't
seem to find it. Below I create a custom tick formatter and turn offsets.
There may be a better way to do this.

If this isn't the bug you were suggesting, please clarify.

Best,
-Tony

#~
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
# or `ax = plt.gca()` for older versions of matplotlib

y = 1e9
ax.plot([y, y+1])
ax.yaxis.set_major_formatter(plt.ScalarFormatter(useOffset=False))

plt.show()
#~
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen

2012-04-26 Thread Tony Yu
On Thu, Apr 26, 2012 at 12:51 PM, willfurnass  wrote:

>
> I've converted a simple MATLAB script [1] for wavelet decomposition-based
> analysis to Python.  I now want to create figures similar to [2] that
> feature five subplots in one column, with the 1st and 3rd being generated
> using 'subplot.plot' and the others being generated using 'subplot.imshow'.
>
> I want to find a way of scaling the  x and y axes of all subplots so that
> they're the same size on screen across all subplots.  Unfortunately I can't
> find any combination of 'aspect' or 'extent' that will let me do this.  I
> should note that I've added colorbars to all my image plots; the problem
> exists regardless of whether these are used.
>
> Has anyone got any suggestions?  Apologies if this is a trivial matter; I'm
> fairly new to MP.
>
> FYI I'm using matplotlib v1.1.0.
>
> [1]
>
> http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis
> [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg
>
> Regards,
>
> Will Furnass
>
>
You could try

fig, axes = plt.subplots(nrows=5, sharex=True, sharey=True)

And then call `axes[0].plot(...)` and `axes[1].imshow(...)`. You could also
unpack the axes array and access them that way (if you prefer):

ax0, ax1, ax2, ax3, ax4 = axes
ax0.plot(...)

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] tight_layout() causes RuntimeError on OSX

2012-05-01 Thread Tony Yu
On Tue, May 1, 2012 at 3:04 PM, Elliot Saba  wrote:

> Hey guys, I'm trying to use tight_layout() to fix up some subplot
> grossness, but whenever I call it, I get:
>
> Traceback (most recent call last):
>   File "test.py", line 16, in 
> plt.tight_layout()
>   File
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py",
> line 1056, in tight_layout
> fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad)
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py",
> line 1415, in tight_layout
> pad=pad, h_pad=h_pad, w_pad=w_pad)
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/tight_layout.py",
> line 117, in auto_adjust_subplotpars
> tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots])
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py",
> line 8396, in get_tightbbox
> bb.append(self.title.get_window_extent(renderer))
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py",
> line 743, in get_window_extent
> bbox, info = self._get_layout(self._renderer)
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py",
> line 296, in _get_layout
> ismath=False)
>   File 
> "/Users//.homebrew/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py",
> line 164, in get_text_width_height_descent
> width, height, descent =
> self.gc.get_text_width_height_descent(unicode(s), family, size, weight,
> style)
> RuntimeError: CGContextRef is NULL
>
> I've googled around, but no answers have been found.  Is this a known
> issue, and if it's not, how can I go about fixing it?
> Thanks,
> -E
>
>
When I run the macosx backend (which appears to be what you're using), I
get the following output:

tight_layout : falling back to Agg renderer

and the figure appears to be rendered with TkAgg . So it appears that it's
a known issue on the macosx backend. And, apparently, the suggested
work-around is to use an Agg backend.

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] modify default figure dpi when saving figure interactivley

2012-05-21 Thread Tony Yu
On Mon, May 21, 2012 at 3:45 AM, Chao YUE  wrote:

> Dear all,
>
> I have a question on how to change default figure dpi when try to save
> figure in interactive mode.
> I try to use mat.rcParams['figure.dpi']=300 before I plot, then the
> problem is that the figure which is drawn is too big for interactive check
> (maybe because of increase in dpi).
> the mat.rcParams['figure.figsize'] is still default [8,6]. The other
> option is that always use fig=gcf(); and fig.savefig('my_plot.jpg',
> dpi=300).
> I am suing 'Agg' backend on ubuntu system.
>
> thanks et cheers,
>
> Chao
>
> Hi Chao,

Have you tried the 'savefig.dpi' rcParam? (see customization
docs
)

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Slow imshow when zooming or panning with several synced subplots

2012-05-23 Thread Tony Yu
On Wed, May 23, 2012 at 9:04 AM, Sergi Pons Freixes
wrote:

> On Wed, May 23, 2012 at 11:00 AM, Guillaume Gay
>  wrote:
> > Hello
> >
> >
> > What is the size of a single image file? If they are very big, it is
> > better to do everything from processing to ploting at once for each file.
>
> As stated below, each image is single-channel, of 4600x3840 pixels. As
> you can see on the code, there is not much processing, just loading
> the images and plotting them. What it's slow is not the execution of
> the code, is the interactive zooming and panning once the plots "are
> in the screen".
>
> >> It's 15 images, single-channel, of 4600x3840 pixels each.
> > This is a lot of data.  8bit or 16bit ?
>
> They are floating point values (for example, from 0 to 45.xxx). If I
> understood correctly, setting the vmin and vmax, matplotlib should
> normalize the values to an appropriate number of bits.
>
>
I'm not sure what you mean by "normalize the values to an appropriate
number of bits", but I don't think setting `vmin` or `vmax` will change the
data type of the image. So if you have 64-bit floating point images (100+
Mb per image), then that's what you're going to be moving/scaling when you
pan and zoom.

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Turning of ticks in matplotlibrc

2012-05-23 Thread Tony Yu
On Mon, May 21, 2012 at 4:01 PM, Andreas Mueller
wrote:

> **
> Hi everybody.
> I have been trying to turn off xticks and yticks and their labels in
> matplotlibrc.
> Tickshave
>  an argument "tick1On" and "label1On" but it seems I can not use these
> in the config file. Is that correct?
> Is there any other way to turn of ticks by default?
>
> Thanks,
> Andy
>
> Hi Andy,

I don't think there are any rc parameters for controlling this, but you can
call `plt.axis('off')` or `ax.set_axis_off()`. I know that's not what you
were looking for, but I thought I'd mention it.

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Slow imshow when zooming or panning with several synced subplots

2012-05-24 Thread Tony Yu
On Thu, May 24, 2012 at 9:14 AM, Sergi Pons Freixes
wrote:

> On Wed, May 23, 2012 at 6:27 PM, Tony Yu  wrote:
> >
> > I'm not sure what you mean by "normalize the values to an appropriate
> number
> > of bits", but I don't think setting `vmin` or `vmax` will change the data
> > type of the image. So if you have 64-bit floating point images (100+ Mb
> per
> > image), then that's what you're going to be moving/scaling when you pan
> and
> > zoom.
>
> I was just guessing that it is part of the process of converting
> actual data (32 bit floats) to images on the screen (24 bit for RGB
> (32 with transparency) or 8 bit for grayscale).
>
> I tried converting the data to 8 bit, with .astype('uint8'), and it
> keeps being poorly responsive on zooming and panning.
>
>
It seems that setting `interpolation='none'` is significantly slower than
setting it to 'nearest' (or even 'bilinear'). On supported backends (e.g.
any Agg backend) the code paths for 'none' and 'nearest' are different:
'nearest' gets passed to Agg's interpolation routine, whereas 'none' does
an unsampled rescale of the image (I'm just reading the code comments
here). Could you check whether changing to `interpolation='nearest'` fixes
this issue?

-Tony

(Note: copied to stackoverflow)

PS: These different approaches *do* give different qualitative results; for
example, the code snippet below gives a slight moiré pattern, which doesn't
appear when `interpolation='none'`. I *think* that 'none' is roughly the
same as 'nearest' when zooming in (image pixels are larger than screen
pixels) but gives a higher-order interpolation result when zooming out
(image pixels smaller than screen pixels). I think the delay comes from
some extra Matplotlib/Python calculations needed for the rescaling.

#~~~
import matplotlib.pyplot as plt
import numpy as np

img = np.random.uniform(0, 255, size=(2000, 2000)).astype(np.uint8)

plt.imshow(img, interpolation='nearest')
plt.show()
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Easy mistake to make...

2012-05-24 Thread Tony Yu
On Thu, May 24, 2012 at 9:54 AM, Benjamin Root  wrote:

> Just got bit by this and I thought I'd share to help others.
>
> I was just quickly writing out some pyplot commands to create two subplots
> to compare some results.  I did:
>
> plt.subplots(1, 2, 1)
> plt.contourf()
> plt.title("Contours")
> xlim = plt.xlim()
> ylim = plt.ylim()
>
> plt.subplots(1, 2, 2)
> plt.imshow()
> plt.title("Raw Image")
> plt.xlim(xlim)
> plt.ylim(ylim)
>
>
> Did you see the error?  I did "subplots" instead of "subplot".  Since the
> third argument for plt.subplot is "sharex", a value of 1 or 2 appears
> perfectly valid to it. Meanwhile, the second call to plt.subplots() throws
> out my first subplot, and I also get the seemingly odd behavior of the
> first subplot having the correct x limits, but the default y limits (0,
> 1).  Of course, this makes sense once you figure out the issue, but it is
> an extra wrinkle that can be quite confusing.
>
> I suspect this is a very easy mistake to make.  Should we perhaps test the
> value of sharex in subplots() and warn if it is anything but a python
> bool?  Just a thought.
>
> Cheers!
> Ben Root
>
>
+1 : I switch `subplots` and `subplot` quite frequently, so a check would
be helpful.

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Dark or inverted color scheme

2012-05-25 Thread Tony Yu
On Fri, May 25, 2012 at 4:07 PM, Tom Aldcroft  wrote:

> Is there a simple way to essentially invert the default plotting color
> scheme so that the figure background is black and all text, ticks,
> axes, axis labels, etc are white?  I think what I want is to redefine
> the RGB definitions of the standard color values 'b', 'y', 'k', etc so
> that I can make a plot figure with a black background using the same
> script as one for the normal white background.
>
> A spent a little while googling and didn't find anything apart from
> specifically setting different colors for every single plot element.
> This would be tiresome.
>
> Thanks in advance for any help,
> Tom
>
>
Hi Tom,

You can create a custom matplotlibrc file [1] and use that for your plots.
The settings you'd probably want to change are copied below. Note that not
all plotting elements grab colors from rc parameters (unfortunately), so
you may find that some functions will ignore these settings.

I think the simplest way (currently) to use the rc file is by putting it in
the same directory as your plotting script (or wherever you're executing
your script). There's a pending pull request [2] that adds the ability to
load rc parameters from a file. Also, I maintain a small set of matplotlib
convenience functions, including a stylesheet-like function. I added the rc
parameters below as a new style and added an example to the documentation
[3].

Hope that helps,
-Tony

[1] http://matplotlib.sourceforge.net/users/customizing.html
[2] https://github.com/matplotlib/matplotlib/pull/861
[3]
http://tonysyu.github.com/mpltools/auto_examples/style/plot_dark_background.html

# rc definitions for dark backgrounds

lines.color: white
patch.edgecolor: white

text.color: white

axes.facecolor: black
axes.edgecolor: white
axes.labelcolor: white

xtick.color: white
ytick.color: white

grid.color: white

figure.facecolor: black
figure.edgecolor: black

savefig.facecolor: black
savefig.edgecolor: black
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Dark or inverted color scheme

2012-05-25 Thread Tony Yu
On Friday, May 25, 2012, Jerzy Karczmarczuk wrote:

>  Tony Yu:
>
> # rc definitions for dark backgrounds
>
>  lines.color: white
> patch.edgecolor: white
>
> ...
>
> don't forget to lighten the colours in axes.color_cycle (unless blue on
> black, etc. suits you). This is used by plot and was one of my numerous
> mistakes two days ago...
>
> Jerzy Karczmarczuk
>
> Indeed: blue on black is a fashion faux pas. ;) Also the default
color_cycle has black in it, so it should be changed, regardless of
aesthetic considerations.
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how does imshow() represent numpy array with origin = "lower" keyword ?

2012-05-30 Thread Tony Yu
On Tue, May 29, 2012 at 5:31 AM, Yasin Selçuk Berber
wrote:

>
> Hi. I want to make sure how imshow shows a numpy array as image.
>
> lets say below is our numpy data array where letter represent data values
> and numbers represent row/col indices.
>
>   0 1 2
> 0 a b c
> 1 d e f
> 2 g h i
>
> and lets think imshow's origin is default upper left.
> Now, if we show our data as an image, the orientation of visual
> representation of data shouldt change,
> and seen like below, right?
>
>   0 1 2
> 0 a b c
> 1 d e f
> 2 g h i
>
> But if we pass origin="lower" keyword to imshow, (as in basemap by
> default);
> is this what we expect to see ?
>
>   0 1 2
> 2 g h i
> 1 d e f
> 0 a b c
>
> To be clear, does imshow with "lower" keyword value;
>
> 1-takes first row of data and put it most bottom,
> 2-then take second row and put it one row upper from most bottom.etc ?
>
> Thanks.
>
> --
> Yasin Selçuk Berber
> "Bismillah, her hayrın başıdır."
>
>
Hi Yasin,

Yes, your interpretation looks correct to me. Image coordinates typically
have an origin at the upper left and increase downward and to the right.
Setting `origin='lower' ` essentially changes `imshow` to use data
coordinates, which typically have an origin at the bottom left and increase
upward and to the right.

Do you expect (or get) something different?

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] question about example of override the default reporting of coords

2012-05-31 Thread Tony Yu
On Thu, May 31, 2012 at 9:31 AM, Mark Bakker  wrote:

> I looked at the example of overriding the default reporting of coords,
> which is here:
>
> http://matplotlib.sourceforge.net/examples/pylab_examples/coords_report.html
>
> from pylab import *
>
> def millions(x):
> return '$%1.1fM' % (x*1e-6)
>
> x = rand(20)
> y = 1e7*rand(20)
>
> ax = subplot(111)
> ax.fmt_ydata = millions
> plot(x, y, 'o')
>
> show()
>
> I don't understand what the millions function does (with a $ and M ?).
> In fact, I get the exact same result when I delete the line
>
> ax.fmt_ydata = millions
>
> Any thoughts?
>

Hi Mark,

It's a bit confusing, but there's actually two different types of
formatters. You're most likely looking for major/minor tick formatters (
example).
In the above example, the *cursor coordinate* is reformatted. In an
interactive window, you should see the current cursor position in the lower
left (this may depend on the backend)---that's the value that should be
reformatted by the `millions` function.

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] question about example of override the default reporting of coords

2012-05-31 Thread Tony Yu
On Thu, May 31, 2012 at 10:03 AM, Mark Bakker  wrote:

> OK. Got it. That is not what I was looking for.
>
> But, why the leading $ sign? Just as an example? The $ sign shows up in
> the cursor coordinate now. Is that what was supposed to happen (it is
> confusing with the $ sign also being used for mathtext formatting, as you
> know).
>
> Thanks,
>
> Mark
>
>
I'm guessing that the example was displaying millions of dollars along the
y-axis. The dollar sign can be confusing, but it's nice to know that the
mathtext parser doesn't get confused ;)

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] easy question on ytick label format

2012-06-01 Thread Tony Yu
>
>
>> On 06/01/2012 02:58 PM, Mark Bakker wrote:
>>
>> Hello List,
>>
>> I want to plot plot([1000,2000])
>> Then on the y-axis, I want labels 1 and 2, and at the top of the y-axis I
>> want E3.
>> This works automatically with plot([1e7,2e7]).
>> But I assume that is something that can be set for plot([1e3,2e3]) as
>> well.
>>
>> I have been browsing the examples, and tried the (for me) obvious things,
>> but couldn't find the answer.
>>
>> Any help is appreciated,
>>
>> Mark
>>
>> Hi Mark,

You can set the (exponent) limits at which scientific notation is activated:

plt.ticklabel_format(scilimits=(-3, 3))

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] ymax

2012-06-06 Thread Tony Yu
On Wed, Jun 6, 2012 at 3:32 PM, kamel maths  wrote:

> Hi,
>
> for this script:
> 
> from pylab import *
>
> fig = figure()
> ax = fig.add_subplot(111)
> ax.axis('equal')
>
> x = linspace(-2, 3, 50)
> ax.plot(x, sin(x))
>
> show()
> -
> If I try to get ymax with ax.get_ylim(), i obtain 1.0 whereas I observe it
> is 2.0.
> How can I obtain 2.0 for ymax ?
>
> Thanks.
>
> Kamel
>

Hi Kamel,

I'm not seeing the same result: I actually get back (-1.94, 1.94) from
`get_ylim`. When do you call `get_ylim`? Do you call it *after* calling
`plot`?

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] ymax

2012-06-07 Thread Tony Yu
On Thu, Jun 7, 2012 at 12:14 PM, kamel maths  wrote:

> Thanks for your answers.
>
> It is not very clear for me yet. This a script I tested.
> --
> from pylab import *
>
> fig = figure()
> ax = fig.add_subplot(111)
> ax.axis('equal')
>
> x = linspace(-2, 3, 50)
> ax.plot(x, sin(x))
>
> ylim = ax.get_ylim()
> print(ylim)
>
> show()
>
> ylim = ax.get_ylim()
> print(ylim)
> 
> With the first print, I obtain (-1,1) and with the second one, after
> having closed the figure showed, I obtain (-1.94,1.94). But I would like to
> obtain (-1.94,1.94) with the first one in order to use this data in the
> figure.
> Is it possible ?
>
>
Hi Kamel,

(I'm recopying to the list; unfortunately, the mailing list doesn't do this
automatically)

Well, this is strange: I swear I tested this yesterday, and I got (-1.94,
1.94) when calling `get_ylim` before `show`. But when I test this today, I
get (-1, 1) with the call before `show`.

I guess the initial call to `get_ylim` returns that data limits (which are
(-1, 1) in this case), but the call to  `axis('equal')` results in a
rescaling at draw time.

If you're just trying to readjust the plot before the plot blocks
execution, you can run `draw()` right before calling `get_ylim`. There may
be a better approach, though.

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] y-axis misbehavior

2012-06-07 Thread Tony Yu
On Thu, Jun 7, 2012 at 3:44 PM, Mark Gurling  wrote:

> I am on Ubuntu 11.10
> matplotlib version 1.1.0
> numpy version 1.5.1
>
> I have two bar graph scripts (good.py and bad.py). Each generates a graph
> that contains two bars: one bar that extends along the positive y-axis and
> another bar that extends along the negative y-axis. The only difference
> between the two scripts is that in good.py the positive bar extends to
> 69.0, but in bad.py it extends to 70.0; however, while in good.py the
> y-axis ends precisely at -30.0, in bad.py the y-axis ends below -30.0
> despite the yticks setting specified on line 20. Is there an explanation
> for this behavior? How might I remedy this?
>
>
`yticks()` just sets the ticks, which shows up correctly in both plots. It
sounds like what you want to specify is the axis limit. You can add the
following (e.g. after the call to `yticks`):

   plt.ylim(ymin=-30)

As for the reason, it has to do with creating axes sizes that fit all the
elements within the plot area and also allow ticks that are "nicely"
spaced. You just happen to be near the threshold of two different spacings,
I think.

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] legend label for fill_between (or similar)

2012-06-21 Thread Tony Yu
On Thu, Jun 21, 2012 at 4:09 PM, Andre' Walker-Loud wrote:

> Hi All,
>
> Sometimes, instead of using data points with error bars, I instead use
> fill_between to create a little bar, with a band which I use alpha=.3 or so.
>
> I have tried unsuccessfully to find an easy way to create a legend label
> for this band - I am trying to have a similar band appear in my legend.
>
> I am not attached to fill_between if there is a similar way to create such
> a "little bar" to represent my data point.
>
>
> Thanks,
>
> Andre
> --
>
> Hi Andre,

Unfortunately, I think the preferred method is to create a proxy artist:

http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist

Basically, you draw a fake patch with the same parameters as your fill (see
example below).

Hope that helps,
-Tony

# example from
http://comments.gmane.org/gmane.comp.python.matplotlib.general/29476
def fill_between(x, y1, y2=0, ax=None, **kwargs):
"""Plot filled region between `y1` and `y2`.

This function works exactly the same as matplotlib's fill_between,
except
that it also plots a proxy artist (specifically, a rectangle of 0 size)
so that it can be added it appears on a legend.
"""
ax = ax if ax is not None else plt.gca()
ax.fill_between(x, y1, y2, **kwargs)
p = plt.Rectangle((0, 0), 0, 0, **kwargs)
ax.add_patch(p)
return p
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] tornado chart

2012-06-21 Thread Tony Yu
On Thu, Jun 21, 2012 at 6:42 PM, Alan G Isaac  wrote:

> I never thought it would happen, but the
> Matplotlib Gallery has for once failed me:
> http://matplotlib.sourceforge.net/gallery.html
>
> I was looking for an example of creating a nice
> tornado chart:
>
> http://code.enthought.com/projects/chaco/docs/html/user_manual/tutorial_1.html
> http://www.tushar-mehta.com/excel/software/tornado/
> http://www.juiceanalytics.com/writing/recreating-ny-times-cancer-graph/
>
> A basic version will do, say along the lines of
> the Chaco example.
>
> Thanks for any leads,
> Alan Isaac
>
>
Hi Alan,

Here's an example based off the horizontal bar charts in the gallery. There
may be a better way to align the y-tick labels (the example manually tweaks
the x-offset), but I don't know how to do it off the top of my head.
Alternatively, you could put the ticks on the left and squish the space
between subplots (using `subplots_adjust(wspace=0)` but then you run into
the issue of overlapping x-tick labels.

Hope that helps,
-Tony

# tornado chart example
import numpy as np
import matplotlib.pyplot as plt


people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
num_people = len(people)

time_spent = np.random.uniform(low=5, high=100, size=num_people)
proficiency = np.abs(time_spent / 12. + np.random.normal(size=num_people))
pos = np.arange(num_people) + .5# bars centered on the y axis

fig, (ax_left, ax_right) = plt.subplots(ncols=2)
ax_left.barh(pos, time_spent, align='center', facecolor='cornflowerblue')
ax_left.set_yticks([])
ax_left.set_xlabel('Hours spent')
ax_left.invert_xaxis()

ax_right.barh(pos, proficiency, align='center', facecolor='lemonchiffon')
ax_right.set_yticks(pos)
# x moves tick labels relative to left edge of axes in axes units
ax_right.set_yticklabels(people, ha='center', x=-0.08)
ax_right.set_xlabel('Proficiency')

plt.suptitle('Learning Python')

plt.show()
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Event handling... again

2012-07-04 Thread Tony Yu
On Wed, Jul 4, 2012 at 10:14 PM, Jorge Scandaliaris
wrote:

> Hi,
> Are there any caveats when using events together with IPython that you
> are aware of? I have some code that I use to interactively explore
> images that works OK when run from a Python interpreter but does not
> (see note) when run from IPython. With --pylab option the problems are
> more evident, but don't disappear completely without it. If I test
> with some of the examples (i.e.
> http://matplotlib.sourceforge.net/examples/event_handling/data_browser.html
> ),
> they work OK in both cases. I can't really post a working example, as
> my code has grown large, and I am still trying to pin point the root
> cause. I am posting also at the IPython ml, who knows
>
> I'll appreciate any hints and or related problems you might have had,
> that help me find a solution to this.
>
> Jorge
>
>
> Note: Does not run refers to *some* of the event handling defined not
> working, for example I have defined specific keys that trigger the
> loading of a new image
>
>
Just a wild guess: Any chance you're using some GUI-toolkit-specific
functionality?

-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Event handling... again

2012-07-04 Thread Tony Yu
On Wed, Jul 4, 2012 at 11:11 PM, Jorge Scandaliaris
wrote:

> > De: Tony Yu 
> >
> >
> >Just a wild guess: Any chance you're using some GUI-toolkit-specific
> functionality?
> >
> >
>
>
> Can you elaborate please? I use the GTKAgg backend, and I guess IPython
> has specific mechanisms (I don't know the details) for keeping both the
> plot and the interpreter responsive, that's the --pylab option I mention.
> However, why am I the only asking for help here? Is it that just a few
> people use events and gtk backend and IPython?
> My script, although larger and by now more complex, follows the lines of
> the example I gave earlier...
>
> Jorge
>

Sorry, I wasn't suggesting that it was a problem with the GTK backend; I
was asking if you were explicitly calling GTK.

IPython --pylab starts an event loop for the default matplotlib backend
(you can check this by printing `plt.rcParams['backend']`). If for some
reason your default backend is not GTK and --pylab starts an event loop for
that backend, then GTK-specific calls could cause problems. If this is the
problem, you could set the backend in your matplotlibrc file.
Alternatively, IPython has a -gthread command line option.

Like I said, this just a wild guess. Without example code, it's hard to pin
down.

-Tony

P.S. sorry for the duplicate, Jorge. I forgot to reply-all.
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Increasing font size in axis ticks

2012-07-05 Thread Tony Yu
On Thu, Jul 5, 2012 at 8:12 AM, David Kremer wrote:

> Hello,
>
> I know how one can increase the font size in the xlabel and ylabel
> fields. I use the methode presented in:
>
>
> http://matplotlib.sourceforge.net/examples/pylab_examples/dannys_example.html
>
> But I don't know how to increase the font size for the numbers labelling
> the xticks or the yticks, and found nothing in the doc. May you help ?
>
> David
>
>
Hi David,

You can call `tick_params`; e.g.,

plt.tick_params(labelsize=20)

If you want to change just one axis

ax.xaxis.set_tick_params(labelsize=20)

This assumes your axes object (from `plt.subplots`, `fig.add_subplot`,
`plt.gca()`, etc.) is named `ax` .

Best,
-Tony
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] ANN: mpltools 0.1 release

2012-07-10 Thread Tony Yu
Announcement: mpltools 0.1
==

mpltools is a package of tools for matplotlib. For the most part, these
tools are only loosely-connected in functionality, but there are two that
may prove particularly useful:

Styles and plot2rst
---

The `style` package provides a simple way to define and reuse
matplotlibrc-like config files. For example, there's an included style that
mimics R's plotting package, ggplot. You can use this style by calling::

   from mpltools import style
   style.use('ggplot')

(Thanks to Huy Nguyen for these settings.)

The second tool of note is `plot2rst`, which provides a simple way to
generate (Sphinx-flavored) reStructuredText examples from normal python
files. See the Getting Started page and `plot2rst` example for details:

   http://tonysyu.github.com/mpltools/getting_started.html

http://tonysyu.github.com/mpltools/auto_examples/sphinx/plot_plot2rst.html


Other tools
---

This package provides other tools for tweaking colors, layouts, etc. The
easiest way to get started is to look at the example gallery:

   http://tonysyu.github.com/mpltools/auto_examples/index.html


Download


You can grab the 0.1 release on PyPI:

   http://pypi.python.org/pypi/mpltools/0.1

or clone the repo on github:

   https://github.com/tonysyu/mpltools.git


Contributors


Thanks the following people for reporting bugs and contributing fixes and
enhancements:

- Alex Arsenovic
- Guillaume Calmettes
- Huy Nguyen
- Sergey Karayev

Special thanks to Alex, who came up with an early implementation of
stylesheets that started me down this path.
--
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


  1   2   >