empty83 | 1 Apr 01:06
Picon
Gravatar

legends with fill_between


i can't make a legend for a fill_between and don't understand what i'm doing
wrong.  the following code seems like the most obvious way to make a legend
for a fill_between, but does do what i expect.  the code plots, but
complains that "No labeled objects found."  any help would be much
appreciated.

from pylab import fill_between, legend, show
a = [0,1,2,4,5]
b = [1,1,1,1,1]
c = [0,1,2,4,5]
fill_between(a,b,c,label='hi')
legend()
show() 
--

-- 
View this message in context: http://www.nabble.com/legends-with-fill_between-tp22816609p22816609.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Lorenzo Isella | 1 Apr 12:50
Picon

Plotting Scalar on a Circular Grid

Dear All,
I am having a hard time with something which must be fairly doable: I
would like to plot a simple scalar function on a circular domain.
Consider for instance a trivial modification of one of the online examples:

Code 1

#!/usr/bin/env python
"""
See pcolor_demo2 for a much faster way of generating pcolor plots
"""
from __future__ import division
from pylab import *

def func3(x,y):
    return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2)

def func4(x,y):
    theta=arcsin(y)
    return cos(theta)

# make these smaller to increase the resolution
dx, dy = 0.05, 0.05

x = arange(-1.0, 1.0, dx)
y = arange(-1.0, 1.0, dy)
X,Y = meshgrid(x, y)

Z = func4(X, Y)

(Continue reading)

oyarsa the old | 1 Apr 14:22
Picon

embedding figures inside another (coordinates)

Hello,

I am new to matplotlib and pylab.
I have an image plotted with imshow/contour, or even just a coordinate system plotted with axis.

I need to plot smaller contours/images on them at selected pixels. The only way I can figure how to do that is using axes. However, axes is defined on normalised coordinates which cover the entire window, whereas the axis of the main figure is drawn within it, with some margin.

My problem is how to get the correct coordinates for plotting each of the smaller figures ? The easiest way to do so would be to get the normalised coordinates of the rectangle which is drawn by axis. Is there a way to get that?

Thanks
Mohan.

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Jae-Joon Lee | 1 Apr 19:02
Picon
Gravatar

Re: legends with fill_between

The matplotlib legend does not currently support fill_between. As a
matter of fact, fill_between command creates RegularPolyCollection
artist, and the mpl legend does not know how to handle this kind of
artist at this time. And I personally do not have good idea how to
draw a handle for this (a simple rectangle box like the handles for
the Patch?). Any suggestion is welcomed.

Meanwhile, you may draw an artist out of your axes area and use this
for the legend entry. For example, for simple a rectangle handle,

from pylab import fill_between, legend, show
a = [0,1,2,4,5]
b = [1,1,1,1,1]
c = [0,1,2,4,5]
fb = fill_between(a,b,c,label='hi')

from matplotlib.patches import Rectangle
r = Rectangle((0, 0), 1, 1) # creates rectangle patch for legend use.

legend([r], ["hi"])
show()

-JJ

On Tue, Mar 31, 2009 at 7:06 PM, empty83 <matt.terry <at> gmail.com> wrote:
>
> i can't make a legend for a fill_between and don't understand what i'm doing
> wrong.  the following code seems like the most obvious way to make a legend
> for a fill_between, but does do what i expect.  the code plots, but
> complains that "No labeled objects found."  any help would be much
> appreciated.
>
> from pylab import fill_between, legend, show
> a = [0,1,2,4,5]
> b = [1,1,1,1,1]
> c = [0,1,2,4,5]
> fill_between(a,b,c,label='hi')
> legend()
> show()
> --
> View this message in context: http://www.nabble.com/legends-with-fill_between-tp22816609p22816609.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Jae-Joon Lee | 1 Apr 19:54
Picon
Gravatar

Re: embedding figures inside another (coordinates)

This thread might be helpful.

http://thread.gmane.org/gmane.comp.python.matplotlib.general/16373

Take a look at the above thread and see if it fits your need.

However, it became tricky if your axes adjust its position (e.g.,
aspect=1) during the drawing time.
The example below will be helpful in those case (you need recent
version of matplotlib for this, see if your axes has
"set_axes_locator" method), but this requires some knowledge on how
mpl works.

import matplotlib.transforms

class InsetPosition(object):
    def __init__(self, parent, lbwh):
        self.parent = parent
        self.lbwh = lbwh # position of the inset axes in the
normalized coordinate of the parent axes

    def __call__(self, ax, renderer):
        bbox_parent = self.parent.get_position(original=False)
        trans = matplotlib.transforms.BboxTransformTo(bbox_parent)
        bbox_inset = matplotlib.transforms.Bbox.from_bounds(*self.lbwh)
        bb = matplotlib.transforms.TransformedBbox(bbox_inset, trans)
        return bb

ax = gca()
ax.set_aspect(1.)
axins = axes([0, 0, 1, 1])
ip = InsetPosition(ax, [0.5, 0.1, 0.4, 0.2])
axins.set_axes_locator(ip)

IHTH,

-JJ

On Wed, Apr 1, 2009 at 8:22 AM, oyarsa the old <oyarsa42@...> wrote:
> Hello,
>
> I am new to matplotlib and pylab.
> I have an image plotted with imshow/contour, or even just a coordinate
> system plotted with axis.
>
> I need to plot smaller contours/images on them at selected pixels. The only
> way I can figure how to do that is using axes. However, axes is defined on
> normalised coordinates which cover the entire window, whereas the axis of
> the main figure is drawn within it, with some margin.
>
> My problem is how to get the correct coordinates for plotting each of the
> smaller figures ? The easiest way to do so would be to get the normalised
> coordinates of the rectangle which is drawn by axis. Is there a way to get
> that?
>
> Thanks
> Mohan.
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

------------------------------------------------------------------------------
empty83 | 1 Apr 21:50
Picon
Gravatar

Re: legends with fill_between


I understand why things were not behaving as I expected and I don't really
have any good ideas on how to make a legend from a RegularPolyCollection in
general.

However, I do not grok why fill_between returns a RegularPolyCollection
rather than a Polygon (like fill does).  Does fill_between(x,y0,y1) differ
substantially from fill(x+x[::-1], y0+y1[::-1])?  To me this seems like the
most intuitive behavior.

-matt

Jae-Joon Lee wrote:
> 
> The matplotlib legend does not currently support fill_between. As a
> matter of fact, fill_between command creates RegularPolyCollection
> artist, and the mpl legend does not know how to handle this kind of
> artist at this time. And I personally do not have good idea how to
> draw a handle for this (a simple rectangle box like the handles for
> the Patch?). Any suggestion is welcomed.
> 

--

-- 
View this message in context: http://www.nabble.com/legends-with-fill_between-tp22816609p22834285.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
John Hunter | 1 Apr 22:18
Picon
Gravatar

Re: legends with fill_between

On Wed, Apr 1, 2009 at 2:50 PM, empty83 <matt.terry@...> wrote:
>
> I understand why things were not behaving as I expected and I don't really
> have any good ideas on how to make a legend from a RegularPolyCollection in
> general.
>
> However, I do not grok why fill_between returns a RegularPolyCollection
> rather than a Polygon (like fill does).  Does fill_between(x,y0,y1) differ
> substantially from fill(x+x[::-1], y0+y1[::-1])?  To me this seems like the
> most intuitive behavior.

Because fill_between handles masks, it uses a collection (a
PolyCollection, not a RegularPolyCollection) rather than a simple
Polygon.  For example, see the use of the "where" argument in the
second plot at

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

The simplest way to handle this for the legend is probably to create a
proxy Rectangle with the same properties as the first element in the
poly collection.  Since it is not designed to support multiple
properties for the different fill regions, we might be able to improve
this from a design and performance perspective by using a complex Path
instead of a PolyCollection.

In the interim, you can always manually create a legend using a proxy
Rectangle passed in as a handle to the legend, though admittedly this
is much more cumbersome.

JDH

------------------------------------------------------------------------------
Picon
Picon

Re: error bars on a log log plot

I tried to look at the code (axes.py I presume) in order to attempt a 
patch, but it defeated me, I do not have the  instructions to navigate 
through this code :)
Where is the actual transform of the error bars occurring?
thanks,
Johann

Michael Droettboom wrote:
> I have to say I don't really have a lot of experience with error bars 
> on log plots -- but the root cause here is that the lower bound of the 
> error bar goes negative, and as we all know, the log of a negative 
> number is undefined.  If you can suggest where the lower bound should 
> be drawn or provide third-party examples, I'm happy to look into this 
> further and resolve this "surprise".
>
> Mike
>
> Cohen-Tanugi Johann wrote:
>> yes exactly....
>> I should have provided a test case, thanks for following up!
>> Johann
>>
>> Matthias Michler wrote:
>>  
>>> Hello Johann,
>>>
>>> is the problem you are reporting the one I observe in the attached 
>>> picture? Namely some vertical and horizontal lines are missing when 
>>> using yscale="log". More precisely everything below y=1 seems to be 
>>> missing.
>>>
>>> The picture was generated with the code below and
>>> matplotlib.__version__ = '0.98.6svn'
>>> matplotlib.__revision__ = '$Revision: 6887 $'
>>>
>>> best regards Matthias
>>>
>>> ###############################
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>>
>>> plt.subplot(111, xscale="log", yscale="log")
>>> x = 10.0**np.linspace(0.0, 2.0, 20)
>>> y = x**2.0
>>> plt.errorbar(x, y, xerr=0.1*x, yerr=5.0+0.75*y)
>>> plt.show()
>>> ################################
>>> On Friday 27 March 2009 16:12:12 Cohen-Tanugi Johann wrote:
>>>      
>>>> Hello, what is the best way to get log log plots with error bars? I
>>>> tried putting log10() everywhere but as I was afraid results look 
>>>> ugly....
>>>> thanks,
>>>> johann
>>>>    
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> ------------------------------------------------------------------------------ 
>>>>
>>>>     
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> _______________________________________________
>>>> Matplotlib-users mailing list
>>>> Matplotlib-users@...
>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>>           
>>
>> ------------------------------------------------------------------------------ 
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@...
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>   
>

------------------------------------------------------------------------------
Michael Hearne | 1 Apr 23:29
Picon
Favicon

compound conditions with pylab.find

Is it possible to use multiple conditionals with the pylab.find() function?

For example, in Matlab, I can do the following:

x = rand(1,10);
i = find(x > 0.5 & x < 0.9); %returns the indices between 0.5 and 0.9

In Python: (ipython -pylab)
x = rand(1,10)

None of the following approaches work:
#i = find(x > 0.5 and x < 0.9)
#i = find(x > 0.5 && x < 0.9)
#i = find(x > 0.5 & x < 0.9)

I'm pretty certain there is some other way to do this using a numpy 
method, and if that's all there is, then I will happily use it.

However, if the goal of the pylab module is to achieve (some level of) 
compatibility with Matlab, then may I suggest this sort of functionality 
be added to the pylab.find() function?

Thanks,

Mike

------------------------------------------------------------------------------
Jeff Whitaker | 1 Apr 23:50
Favicon

Re: compound conditions with pylab.find

Michael Hearne wrote:
> Is it possible to use multiple conditionals with the pylab.find() function?
>
> For example, in Matlab, I can do the following:
>
> x = rand(1,10);
> i = find(x > 0.5 & x < 0.9); %returns the indices between 0.5 and 0.9
>
> In Python: (ipython -pylab)
> x = rand(1,10)
>
> None of the following approaches work:
> #i = find(x > 0.5 and x < 0.9)
> #i = find(x > 0.5 && x < 0.9)
> #i = find(x > 0.5 & x < 0.9)
>
> I'm pretty certain there is some other way to do this using a numpy 
> method, and if that's all there is, then I will happily use it.
>
> However, if the goal of the pylab module is to achieve (some level of) 
> compatibility with Matlab, then may I suggest this sort of functionality 
> be added to the pylab.find() function?
>
> Thanks,
>
> Mike
>   

Mike:  Use numpy.logical_and/numpy.logical_or for elementwise logical 
operations. In your case,

find(logical_and(x>0.5,x<0.9))

works, as does using parantheses

find((x > 0.5) & (x < 0.9))

-Jeff

------------------------------------------------------------------------------

Gmane