Re: [Matplotlib-users] matplotlib and pyside..

2011-07-20 Thread Gerald Storer

Have a closer look at the example I gave.

The currently released version of matplotlib doesn't support PySide at 
all.  So I cheated and simply drew to the generic Agg backend and then 
copied the whole figure (gcf = get current figure) into a PySide QImage 
object at the end.  The QImage can then be displayed however you want 
inside your Qt application.  I used a QGraphicsScene but there are other 
options.


If you really wanted to I guess you could use FigureCanvasAgg as an 
intermediary - but the process is fundamentally different.  You can't 
just drop that it into your PySide app as a widget like you can with 
FigureCanvasQTAgg.


As mentioned earlier, if you'd like to use the same code simply wait for 
the next release of matplotlib which will support PySide or you can get 
a copy of the source from github master today that also support PySide.


Gerald.

On 20/07/2011 3:59 PM, lionel chiron wrote:

Hi Gerald,

I found yesterday interesting informations on a forum where you 
answered about Matplotlib and pyside .. but some details are missing 
to make what I want.
Few days ago I developped stuff in PyQt I 'd like to recuperate in 
Pyside.. the central difficulty is to import Matplotlib in Pyside.
In PyQt I was using FigureCanvasQTAgg but in Pyside I couldn't find 
something equivalent allowing to link Mpl and pyside..
It seems you're able to make drawings (with add.patch) but how to do 
for inserting a figure?


Thanks

Best

Lionel



--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Customize Tick Labels with Axis Artist

2011-07-20 Thread Jae-Joon Lee
There could be a few ways. What I recommend as a matter of fact is to
use other method to draw gridlines. On the other hand, given that you
have a working example, it could be better to have different axis to
draw ticklabels in locations where you want. Here is a diff.

Regards,

-JJ

*** qqwee2.py   2011-07-20 22:02:37.973960916 +0900
--- qqwee.py2011-07-20 22:04:46.063960883 +0900
***
*** 36,41 
--- 36,60 
 ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
 fig.add_subplot(ax1)

+grid_locator1 = FixedLocator([j-0.5*pi for j in theta[::10]])
+grid_locator2 = FixedLocator([i for i in rad[::5]])
+
+grid_helper2 = floating_axes.GridHelperCurveLinear(tr,
+extremes=(.5*pi-0.17,
-.5*pi+0.17, 120, 1),
+grid_locator1=grid_locator1,
+grid_locator2=grid_locator2,
+tick_formatter1=None,
+tick_formatter2=None,
+)
+
+ax1.axis["left2"] = grid_helper2.new_fixed_axis("left", axes=ax1)
+ax1.axis["left2"].line.set_visible(False)
+ax1.axis["left2"].toggle(ticks=False)
+
+ax1.axis["bottom2"] = grid_helper2.new_fixed_axis("bottom", axes=ax1)
+ax1.axis["bottom2"].line.set_visible(False)
+ax1.axis["bottom2"].toggle(ticks=False)
+
 # create a parasite axes whose transData in RA, cz
 aux_ax = ax1.get_aux_axes(tr)




On Tue, Jul 12, 2011 at 2:12 AM, bhargav vaidya  wrote:
> Hello all,
>
> I need help to have customize tick labels using axis artist.
> My problem is to create a grid representation in polar co-ordinates (see fig) 
> with r = logspace(log(1),log(120),128)
> and theta = linspace(0.17,2.97,64) # in radians
>
> I managed to to create the proper gridlines. But unfortunately I have to 
> remove the tick labels as the way I describe the grid locator they crowd the 
> axis.
> I would like to choose only certain points on the axis and label them as the 
> plot would look nice.
>
>
> Regards
> Bhargav Vaidya.
>
> Here is my code modified to my need from already existing code found in the 
> web :
>
> from matplotlib.transforms import Affine2D
> import mpl_toolkits.axisartist.floating_axes as floating_axes
>
> import numpy as np
> import  mpl_toolkits.axisartist.angle_helper as angle_helper
> from matplotlib.projections import PolarAxes
> from mpl_toolkits.axisartist.grid_finder import FixedLocator, MaxNLocator, \
>     DictFormatter
>
> def setup_axes2(fig, rect):
>
>    tr = PolarAxes.PolarTransform()
>
>    pi = np.pi
>    rad = np.logspace(np.log(1.),np.log(120.),128) # Radial
>    theta = np.linspace(0.17,2.97,64) # Theta Co-ordinates
>    angle_ticks = [(0, r"$\frac{1}{2}\pi$"),
>                   (.25*pi, r"$\frac{1}{4}\pi$"),
>                   (.5*pi, r"$0$"),
>                   (-.25*pi, r"$\frac{3}{4}\pi$"),
>                   (-0.5*pi, r"$\pi$")]
>    grid_locator1 = FixedLocator([j-0.5*pi for j in theta])
>    #grid_locator1 = FixedLocator([v for v, s in angle_ticks])
>
>
>    grid_locator2 = FixedLocator([i for i in rad])
>
>    grid_helper = floating_axes.GridHelperCurveLinear(tr,
>                                        extremes=(.5*pi-0.17, -.5*pi+0.17, 
> 120, 1),
>                                        grid_locator1=grid_locator1,
>                                        grid_locator2=grid_locator2,
>                                        tick_formatter1=None,
>                                        tick_formatter2=None,
>                                        )
>
>    ax1 = floating_axes.FloatingSubplot(fig, rect, grid_helper=grid_helper)
>    fig.add_subplot(ax1)
>
>    # create a parasite axes whose transData in RA, cz
>    aux_ax = ax1.get_aux_axes(tr)
>
>    aux_ax.patch = ax1.patch # for aux_ax to have a clip path as in ax
>    ax1.patch.zorder=0.9 # but this has a side effect that the patch is
>                        # drawn twice, and possibly over some other
>                        # artists. So, we decrease the zorder a bit to
>                        # prevent this.
>
>    return ax1, aux_ax
> if 1:
>    import matplotlib.ticker as mpltick
>    import matplotlib.pyplot as plt
>    fig = plt.figure(1, figsize=(10, 10))
>
>
>    ax2, aux_ax2 = setup_axes2(fig, 111)
>
>
>    ax2.axis["left"].major_ticklabels.set_visible(False)
>    ax2.axis["bottom"].major_ticklabels.set_visible(False)
>
>    ax2.grid(color='k',linestyle='-',linewidth=0.5)
>
>    plt.show()
>
> Here is the eps file
>
>
>
>
>
> --
> 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/

[Matplotlib-users] 1d heat map

2011-07-20 Thread Pete Shepard
Hello List,

I am trying to use the pylab.contourf(X,Y,Z,100) function but I would like
to mplot a 1 dimensional heatmap instead of a 2 dimensional heatmap, Perhaps
"contourf" is not the solution but I do like these plots.

Any suggestions?

TIA
--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] 1d heat map

2011-07-20 Thread Benjamin Root
On Wed, Jul 20, 2011 at 12:15 PM, Pete Shepard wrote:

> Hello List,
>
> I am trying to use the pylab.contourf(X,Y,Z,100) function but I would like
> to mplot a 1 dimensional heatmap instead of a 2 dimensional heatmap, Perhaps
> "contourf" is not the solution but I do like these plots.
>
> Any suggestions?
>
> TIA
>
>
An example image of what you would like to see might be useful.

Ben Root
--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] hot to draw a line connecting a list of points

2011-07-20 Thread robert rottermann
hi there,

I would like to draw a a set of lines on top of an image.
Somehow I do not get the result I want

these are the points ((267, 140), (380, 773), (267, 958))

one of my divers atempts is:

pic = plt.imread('../hlwd/effizienz_balken_01.jpg')
pic = np.fliplr(np.rot90(pic, k=2))
plt.imshow(pic)

frame1 = plt.gca()

lx = []
ly = []
for pt in ((267, 140), (380, 773), (267, 958)):
 lx.append(pt[0])
 ly.append(pt[1])
x,y = np.array([lx, ly])
line = mlines.Line2D(x, y, lw=5., alpha=0.4)

frame1.add_line(line)

plt.show()

which produces on line instad of two.

thanks for any pointers
robert


--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread C M
Sorry, this is super-simple, but I'm lost in the whole
locator/formatter part of the docs.

How can I make a locator that just places a tick at every multiple of
0.5 around the data?  So the y axis would look like:

3.5 --
3.0 --
2.5 --
2.0 --
1.5 --
1.0 --

etc.

Thanks,
Che

--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread Buchholz, Greg
>-Original Message-
>From: C M [mailto:cmpyt...@gmail.com] 
>
>Sorry, this is super-simple, but I'm lost in the whole
>locator/formatter part of the docs.
>
>How can I make a locator that just places a tick at every multiple of
>0.5 around the data?  So the y axis would look like:
>
>3.5 --
>3.0 --
>2.5 --
>2.0 --
>1.5 --
>1.0 --

Do you want something like:

ylim(1.0,3.5)
yticks(arrange(1.0,4.0,0.5))



--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread C M
On Wed, Jul 20, 2011 at 7:24 PM, Buchholz, Greg
 wrote:
>>-Original Message-
>>From: C M [mailto:cmpyt...@gmail.com]
>>
>>Sorry, this is super-simple, but I'm lost in the whole
>>locator/formatter part of the docs.
>>
>>How can I make a locator that just places a tick at every multiple of
>>0.5 around the data?  So the y axis would look like:
>>
>>3.5 --
>>3.0 --
>>2.5 --
>>2.0 --
>>1.5 --
>>1.0 --
>
> Do you want something like:
>
>    ylim(1.0,3.5)
>    yticks(arrange(1.0,4.0,0.5))

I'm not sure, because I can't try it out--I'm using the OO matplotlib,
not Pyplot.  What's the equivalent of this in the OO API?

Thanks,
Che

--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread Gökhan Sever
On Wed, Jul 20, 2011 at 5:41 PM, C M  wrote:

> On Wed, Jul 20, 2011 at 7:24 PM, Buchholz, Greg
>  wrote:
> >>-Original Message-
> >>From: C M [mailto:cmpyt...@gmail.com]
> >>
> >>Sorry, this is super-simple, but I'm lost in the whole
> >>locator/formatter part of the docs.
> >>
> >>How can I make a locator that just places a tick at every multiple of
> >>0.5 around the data?  So the y axis would look like:
> >>
> >>3.5 --
> >>3.0 --
> >>2.5 --
> >>2.0 --
> >>1.5 --
> >>1.0 --
> >
> > Do you want something like:
> >
> >ylim(1.0,3.5)
> >yticks(arrange(1.0,4.0,0.5))
>
> I'm not sure, because I can't try it out--I'm using the OO matplotlib,
> not Pyplot.  What's the equivalent of this in the OO API?
>


ax.axis((xmin, xmax, ymin, ymax))
ax.yaxis.set_ticks(np.arange(1.0, 4.0, 0.5))


>
> Thanks,
> Che
>
>
> --
> 10 Tips for Better Web Security
> Learn 10 ways to better secure your business today. Topics covered include:
> Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
> security Microsoft Exchange, secure Instant Messaging, and much more.
> http://www.accelacomm.com/jaw/sfnl/114/51426210/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>



-- 
Gökhan
--
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread C M
On Wed, Jul 20, 2011 at 7:56 PM, Gökhan Sever  wrote:
>
>
> On Wed, Jul 20, 2011 at 5:41 PM, C M  wrote:
>>
>> On Wed, Jul 20, 2011 at 7:24 PM, Buchholz, Greg
>>  wrote:
>> >>-Original Message-
>> >>From: C M [mailto:cmpyt...@gmail.com]
>> >>
>> >>Sorry, this is super-simple, but I'm lost in the whole
>> >>locator/formatter part of the docs.
>> >>
>> >>How can I make a locator that just places a tick at every multiple of
>> >>0.5 around the data?  So the y axis would look like:
>> >>
>> >>3.5 --
>> >>3.0 --
>> >>2.5 --
>> >>2.0 --
>> >>1.5 --
>> >>1.0 --
>> >
>> > Do you want something like:
>> >
>> >    ylim(1.0,3.5)
>> >    yticks(arrange(1.0,4.0,0.5))
>>
>> I'm not sure, because I can't try it out--I'm using the OO matplotlib,
>> not Pyplot.  What's the equivalent of this in the OO API?
>
>
>     ax.axis((xmin, xmax, ymin, ymax))
>     ax.yaxis.set_ticks(np.arange(1.0, 4.0, 0.5))

Thanks.

But in order to use this, I have to know ymin and ymax, based on the
data. But I thought this was the point of the locators--that they
could assign the ticks based on the range of the data and then some
rule about placement of ticks in that range.  But when I look at the
various kinds of locators in the docs, none have a parameter that is
equivalent to the 0.5 above in set_ticks.

Or do they and I just missed it?

--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread Gökhan Sever
On Wed, Jul 20, 2011 at 7:17 PM, C M  wrote:

> On Wed, Jul 20, 2011 at 7:56 PM, Gökhan Sever 
> wrote:
> >
> >
> > On Wed, Jul 20, 2011 at 5:41 PM, C M  wrote:
> >>
> >> On Wed, Jul 20, 2011 at 7:24 PM, Buchholz, Greg
> >>  wrote:
> >> >>-Original Message-
> >> >>From: C M [mailto:cmpyt...@gmail.com]
> >> >>
> >> >>Sorry, this is super-simple, but I'm lost in the whole
> >> >>locator/formatter part of the docs.
> >> >>
> >> >>How can I make a locator that just places a tick at every multiple of
> >> >>0.5 around the data?  So the y axis would look like:
> >> >>
> >> >>3.5 --
> >> >>3.0 --
> >> >>2.5 --
> >> >>2.0 --
> >> >>1.5 --
> >> >>1.0 --
> >> >
> >> > Do you want something like:
> >> >
> >> >ylim(1.0,3.5)
> >> >yticks(arrange(1.0,4.0,0.5))
> >>
> >> I'm not sure, because I can't try it out--I'm using the OO matplotlib,
> >> not Pyplot.  What's the equivalent of this in the OO API?
> >
> >
> > ax.axis((xmin, xmax, ymin, ymax))
> > ax.yaxis.set_ticks(np.arange(1.0, 4.0, 0.5))
>
> Thanks.
>
> But in order to use this, I have to know ymin and ymax, based on the
> data. But I thought this was the point of the locators--that they
> could assign the ticks based on the range of the data and then some
> rule about placement of ticks in that range.  But when I look at the
> various kinds of locators in the docs, none have a parameter that is
> equivalent to the 0.5 above in set_ticks.
>
> Or do they and I just missed it?
>

You can call min and max functions on your data arrays and make adjustments
in your tick placement accordingly.

-- 
Gökhan
--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread Eric Firing
On 07/20/2011 03:17 PM, C M wrote:
> On Wed, Jul 20, 2011 at 7:56 PM, Gökhan Sever  wrote:
>>
>>
>> On Wed, Jul 20, 2011 at 5:41 PM, C M  wrote:
>>>
>>> On Wed, Jul 20, 2011 at 7:24 PM, Buchholz, Greg
>>>   wrote:
> -Original Message-
> From: C M [mailto:cmpyt...@gmail.com]
>
> Sorry, this is super-simple, but I'm lost in the whole
> locator/formatter part of the docs.
>
> How can I make a locator that just places a tick at every multiple of
> 0.5 around the data?  So the y axis would look like:
>
> 3.5 --
> 3.0 --
> 2.5 --
> 2.0 --
> 1.5 --
> 1.0 --

 Do you want something like:

 ylim(1.0,3.5)
 yticks(arrange(1.0,4.0,0.5))
>>>
>>> I'm not sure, because I can't try it out--I'm using the OO matplotlib,
>>> not Pyplot.  What's the equivalent of this in the OO API?
>>
>>
>>  ax.axis((xmin, xmax, ymin, ymax))
>>  ax.yaxis.set_ticks(np.arange(1.0, 4.0, 0.5))
>
> Thanks.
>
> But in order to use this, I have to know ymin and ymax, based on the
> data. But I thought this was the point of the locators--that they
> could assign the ticks based on the range of the data and then some
> rule about placement of ticks in that range.  But when I look at the
> various kinds of locators in the docs, none have a parameter that is
> equivalent to the 0.5 above in set_ticks.
>
> Or do they and I just missed it?

Try MultipleLocator:

from matplotlib.ticker import MultipleLocator
halflocator = MultipleLocator(base=0.5)
ax.xaxis.set_major_locator(halflocator)

etc.

>
> --
> 5 Ways to Improve&  Secure Unified Communications
> Unified Communications promises greater efficiencies for business. UC can
> improve internal communications as well as offer faster, more efficient ways
> to interact with customers and streamline customer service. Learn more!
> http://www.accelacomm.com/jaw/sfnl/114/51426253/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users



--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib and pyside..

2011-07-20 Thread Gerald Storer
The version of PySide doesn't really matter so long as it is reasonably 
new.  You need a newer version of Matplotlib and yes, the Github master 
is newer than the current release.


Gerald.

On 20/07/2011 8:29 PM, lionel chiron wrote:

Hi Gerald again,

I recuperated the Pyside last version the 1.0.4 from Pyside's site but 
I obtained the same error message trying to use my former code (same 
used with PyQt with Figure Canvas)

raise ImportError, "Warning: formlayout requires PyQt4>v4.3"
Is the github version even more recent than this one??
Thanks

Regards
Lionel


2011/7/20 Gerald Storer mailto:g...@mrxtech.com.au>>

Have a closer look at the example I gave.

The currently released version of matplotlib doesn't support
PySide at all.  So I cheated and simply drew to the generic Agg
backend and then copied the whole figure (gcf = get current
figure) into a PySide QImage object at the end.  The QImage can
then be displayed however you want inside your Qt application.  I
used a QGraphicsScene but there are other options.

If you really wanted to I guess you could use FigureCanvasAgg as
an intermediary - but the process is fundamentally different.  You
can't just drop that it into your PySide app as a widget like you
can with FigureCanvasQTAgg.

As mentioned earlier, if you'd like to use the same code simply
wait for the next release of matplotlib which will support PySide
or you can get a copy of the source from github master today that
also support PySide.

Gerald.


On 20/07/2011 3:59 PM, lionel chiron wrote:

Hi Gerald,

I found yesterday interesting informations on a forum where you
answered about Matplotlib and pyside .. but some details are
missing to make what I want.
Few days ago I developped stuff in PyQt I 'd like to recuperate
in Pyside.. the central difficulty is to import Matplotlib in
Pyside.
In PyQt I was using FigureCanvasQTAgg but in Pyside I couldn't
find something equivalent allowing to link Mpl and pyside..
It seems you're able to make drawings (with add.patch) but how to
do for inserting a figure?

Thanks

Best

Lionel







--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] help with code for DurationFormatter

2011-07-20 Thread C M
A runnable code sample is attached.

I'm trying to plot durations in time (sec to hours) on the y axis such
that if you zoom, it changes the units and axis label appropriately.

When run, it looks right.  But, when I zoom on the first point, it is
shown on the y axis at '0.20' minutes.  I would like it to say '12
seconds'.  I would think the FuncFormatter I am trying to use should
be able to do that, but I cannot figure it out.  For now, those
attempts are commented out in the code.

How can I create a formatter such that zooming changes the tick and
axis labels in this way?

Any help is appreciated.  Thanks,

Che


duration_plot.py
Description: Binary data
--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plotting using an image as background

2011-07-20 Thread Charles R Harris
Hi Robert,

On Fri, Jul 15, 2011 at 9:49 AM, robert  wrote:

> Hi there,
> I am all new to mathlib world..
>
> What I try to do is plotting some charts over an image.
> I would be very grateful, if somebody could provide me with an example.
> thanks
> robert
>
>
I just did this myself with this code:

def make_cutouts(h5file, band=1, vmin=None, vmax=None, dir='.'):
"""Browse pixel data by pixel selection

A shift-left-click on a pixel in ``image`` creates a plot of
the response data for that pixel. A shift--click on the
resulting plot will save it to two files in ``dir`` whose names
are of the form cutout-xcen-ycen.{dat,png}, where xcen and ycen
are replaced with the location of image center. The png file is
an rgb img, the dat file is raw uint16 data.

Parameters
--
h5file : string
Path to h5 file containing image data.
band : int
Band to use. Must be 0 or 1.
vmax, vmin : float, optional
Maximum and minimum values to which the image will be scaled.
dir : string, optional
Path to directory in which plots will be saved.

"""
import matplotlib.pyplot as plt
import h5py
from widgets import Button

# get image data here so that it gets compiled into onclick
fin = h5py.File(h5file, 'r')
img = fin['band%d' % band][...]
src = fin['/'].attrs['input_filename']
fin.close()
m, n = img.shape
# make points for drawing square cutout
xcor = np.array([-128,  128, 128, -128, -128], dtype=float)/10
ycor = np.array([-128, -128, 128,  128, -128], dtype=float)/10

def save(fig, mouse, data):
def onclick(event):
if event.button == 1:
xcen = mouse.xdata
ycen = mouse.ydata
i = int(xcen + .5)*10
j = int(ycen + .5)*10

# write data to file
path = os.path.join(dir, 'cutout-%05d-%05d' % (i,j))
fout = h5py.File(path + '.h5', 'w')
fout.create_dataset('image', data.shape, data.dtype)
fout['/'].attrs['input_filename'] = src
fout['/'].attrs['x_center_pixel'] = i
fout['/'].attrs['y_center_pixel'] = j
fout['image'][...] = data
fout.close()
fig.savefig(path + ".png")
# draw square around cutout
mouse.inaxes.plot(xcen + xcor, ycen + ycor, 'r', lw=2)
mouse.canvas.draw()

return onclick

def onclick(event):
mouse = event.mouseevent
if mouse.button == 1 and mouse.key == "shift":
i = int(mouse.xdata + .5)*10
j = int(mouse.ydata + .5)*10
src_axs = mouse.inaxes
ul_x = max(0, i - 128)
ul_y = max(0, j - 128)
lr_x = min(n, i + 128)
lr_y = min(m, j + 128)
data = img[ul_y:lr_y, ul_x:lr_x]
#
newfig = plt.figure()
newfig.subplots_adjust(top=.90)
# add save button
butax = newfig.add_axes([0.45, .92, .1, 0.04])
button = Button(butax, 'Save', color='red', hovercolor='gold')
button.on_clicked(save(fig, mouse, data))
# display image of cutout
axs = newfig.add_subplot(111)
tmp = axs.imshow(data)
newfig.colorbar(tmp)
newfig.show()

fig = plt.figure()
axs = fig.add_subplot(111)
tmp = axs.imshow(img[::10, ::10], vmin=vmin, vmax=vmax, origin='lower',
picker=True)
xmin, xmax, ymin, ymax = np.array(tmp.get_extent()) + .5
axs.set_xticks([t for t in axs.get_xticks() if t >= 0 and t <= xmax])
axs.set_yticks([t for t in axs.get_yticks() if t >= 0 and t <= ymax])

fig.canvas.mpl_connect("pick_event", onclick)
fig.show()

Which is probably more complex than what you need. What it does is display a
thumbnail of a very large image on which you can shift-click to blowup a
256x256 portion in a separate figure. If you then click the (custom) save
button on the blowup it saves the data together with a thumbnail and plots a
square around the cutout pixels in the original image. The tricky part is
that the image axis generally starts at -.5 and this will cause problems as
the plot will want to put up it's own ticks that excede the image bounds and
you will get big white borders where you don't want them. Hence I call
axs.set_xticks etc. to remove the offending ticks. To bad the image itself
doesn't make its own ticks available.

I had to rewrite the button code to make this work as the first click
handler takes the button with it when it exits as the figure doesn't keep a
reference to it, but that is another problem ;)

Chuck
--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communicatio

Re: [Matplotlib-users] simple question about locator every 0.5

2011-07-20 Thread C M
> Try MultipleLocator:
>
> from matplotlib.ticker import MultipleLocator
> halflocator = MultipleLocator(base=0.5)
> ax.xaxis.set_major_locator(halflocator)
>
> etc.

Thanks, that works for me.  I didn't think I could use non-integers
(0.5) because the docs said, "Set a tick on every integer that is
multiple of base in the view interval".  Earlier in that page, though,
it does say base can be an integer or float.

Che

--
5 Ways to Improve & Secure Unified Communications
Unified Communications promises greater efficiencies for business. UC can 
improve internal communications as well as offer faster, more efficient ways
to interact with customers and streamline customer service. Learn more!
http://www.accelacomm.com/jaw/sfnl/114/51426253/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users