Axes Scaling

Hi Python World!

I currently have a 2D array: A[i][j] which I can plot very nicely
using the contourf function. However, in this plot, the axes span
from (0, i) and (0, j).
I would like to multiply each axes by a scaling constant- thereby
turning the array element values into physical quantities (distance
and time for example).
Could anyone help me with this? I've looked around, but so far the
only solution I have found is to create a new set of arrays with these
scaling factors included. I can do this, but I feel as though it
would be a waste.

···

--
Thanks!
François

Hi François,

Why would it be a waste to multiply the values in an array by the scaling factors?

Can you provide an example of your code so everybody can get a better idea of what you’re doing now?

Thanks,

Alexa

···

On Fri, Feb 17, 2012 at 9:07 AM, Francois Lemery <francois.lemery@…1896…> wrote:

Hi Python World!

I currently have a 2D array: A[i][j] which I can plot very nicely

using the contourf function. However, in this plot, the axes span

from (0, i) and (0, j).

I would like to multiply each axes by a scaling constant- thereby

turning the array element values into physical quantities (distance

and time for example).

Could anyone help me with this? I’ve looked around, but so far the

only solution I have found is to create a new set of arrays with these

scaling factors included. I can do this, but I feel as though it

would be a waste.

Thanks!

François


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi,
Sorry for not giving sufficient detail.
I open an HDF5 file and then read some EArray into a regular array:

a = f.root
MySource = a.myLineSource[:,:,1] # the dimensions of my source
are (x, t) = (50, 15000) 50 corresponds to 50 gridpoints where I have
recorded an electric field. and 15,000 corresponds to the number of
timesteps I have run in my simulation.

figure()
A1=contourf(MySource) # When I do this, it gives me a
beautiful plot. However the x axis spans (0, 50) when I would like it
to go from (0, 50)*DX.
Similarly, in time, my plot spans (0, 15,000) when I would like it to
range from (0, 15000)*DT
Where DX and DT are some real numbers (e.g. a micron, and a femtosecond.)

I would suspect there to be some 'scaling' feature already available
in python for just this kind of thing. That is why I argued that
introducing new arrays to incorporate the adjusted/properly scaled
values would be a waste.
Thanks again!

···

On Fri, Feb 17, 2012 at 1:26 PM, Alexa Villaume <alexa7890@...287...> wrote:

Hi François,

Why would it be a waste to multiply the values in an array by the scaling
factors?

Can you provide an example of your code so everybody can get a better idea
of what you're doing now?

Thanks,
Alexa

On Fri, Feb 17, 2012 at 9:07 AM, Francois Lemery <francois.lemery@...985.....> > wrote:

Hi Python World!

I currently have a 2D array: A[i][j] which I can plot very nicely
using the contourf function. However, in this plot, the axes span
from (0, i) and (0, j).
I would like to multiply each axes by a scaling constant- thereby
turning the array element values into physical quantities (distance
and time for example).
Could anyone help me with this? I've looked around, but so far the
only solution I have found is to create a new set of arrays with these
scaling factors included. I can do this, but I feel as though it
would be a waste.

--
Thanks!
François

------------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Thanks,
François

Francois Lemery :

Hi Python World!

I currently have a 2D array: A[i][j] which I can plot very nicely
using the contourf function. However, in this plot, the axes span
from (0, i) and (0, j).
I would like to multiply each axes by a scaling constant- thereby
turning the array element values into physical quantities (distance
and time for example).
Could anyone help me with this? I've looked around, but so far the
only solution I have found is to create a new set of arrays with these
scaling factors included. I can do this, but I feel as though it
would be a waste.

You want just to change your labelling?
No problemo, Baby.

xmin,xmax = ........
ymin,ymax = ........
...
tbl=...

ic=contourf(tbl,
             extent=(xmin,xmax,ymin,ymax))
axis([xmin,xmax,ymin,ymax])

show()

···

====

Bon courage.

Now, if you want to change your *values*, as Alexa understood, then be more precise, please.

Jerzy Karczmarczuk

I am embedding a matplotlib canvas in a Pyside GUI and wanted to attach a slider to adjust the color scale of a 2D plot made using NonUnitformImage. I am connecting the slider value to im.set_clim([vmin,vmax]). I have got my axis sliders to work, but the intensity slider only adjusts the colorbar without touching the image itself. Is there some trick to making this work with NonUniformImage?

My plotting routine has the following code:

            ax = plt.gca()
            im = NonUniformImage(ax, extent=extent, origin=None, **opts)
            im.set_data(x,y,z)
            ax.images.append(im)
            self.imgplot = im
            plt.colorbar(im)

while the Pyside slot has:

        zhi = self.zmin + (self.ztab.maxslider.value() * range / 100)
        im = self.imgplot
        im.set_clim([zlo,zhi])

The slider dynamically adjusts the colorbar beautifully, but leaves the color plot untouched. Any suggestions welcome.

Thanks in advance,
Ray

···

--
Ray Osborn
Materials Science Division
Argonne National Laboratory
Argonne, IL 60439, USA
Phone: +1 (630) 252-9011
Email: ROsborn@...3972...

Without a more complete example, it is hard to say. Can you make a small stand-alone example that we can try out?

Ben Root

···

On Friday, February 17, 2012, Ray Osborn wrote:

I am embedding a matplotlib canvas in a Pyside GUI and wanted to attach a slider to adjust the color scale of a 2D plot made using NonUnitformImage. I am connecting the slider value to im.set_clim([vmin,vmax]). I have got my axis sliders to work, but the intensity slider only adjusts the colorbar without touching the image itself. Is there some trick to making this work with NonUniformImage?

My plotting routine has the following code:

        ax = plt.gca()

        im = NonUniformImage(ax, extent=extent, origin=None, **opts)

        im.set_data(x,y,z)

        ax.images.append(im)

        self.imgplot = im

        plt.colorbar(im)

while the Pyside slot has:

    zhi = self.zmin + (self.ztab.maxslider.value() * range / 100)

    im = self.imgplot

    im.set_clim([zlo,zhi])

The slider dynamically adjusts the colorbar beautifully, but leaves the color plot untouched. Any suggestions welcome.

Thanks in advance,

Ray

OK - it turns out I can reproduce it in a simple ipython session using ipython --pylab=qt.

I set up an image plot as follows:

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.image import NonUniformImage

x=y=np.linspace(0,2*np.pi,101)

X,Y=np.meshgrid(x,y)

z=sin(X)*sin(Y)

ax=plt.gca()

extent = (x[0],x[-1],y[0],y[-1])

im = NonUniformImage(ax, extent=extent, origin=None)

im.set_data(x,y,z)

ax.images.append(im)

ax.set_xlim(x[0],x[-1])

ax.set_ylim(y[0],y[-1])

plt.colorbar(im)

plt.gcf().canvas.draw()

After that, I try to change the color scale using:

im.set_clim(0,0.5)

plt.gcf().canvas.draw()

The colorbar changes scale, but the plot is untouched. Is that the expected behavior?

Thanks,

Ray

···

On Feb 17, 2012, at 9:05 PM, Benjamin Root wrote:

On Friday, February 17, 2012, Ray Osborn wrote:

I am embedding a matplotlib canvas in a Pyside GUI and wanted to attach a slider to adjust the color scale of a 2D plot made using NonUnitformImage. I am connecting the slider value to im.set_clim([vmin,vmax]). I have got my axis sliders to work, but the intensity slider only adjusts the colorbar without touching the image itself. Is there some trick to making this work with NonUniformImage?

My plotting routine has the following code:

        ax = plt.gca()

        im = NonUniformImage(ax, extent=extent, origin=None, **opts)

        im.set_data(x,y,z)

        ax.images.append(im)

        self.imgplot = im

        plt.colorbar(im)

while the Pyside slot has:

    zhi = self.zmin + (self.ztab.maxslider.value() * range / 100)

    im = self.imgplot

    im.set_clim([zlo,zhi])

The slider dynamically adjusts the colorbar beautifully, but leaves the color plot untouched. Any suggestions welcome.

Thanks in advance,

Ray

Without a more complete example, it is hard to say. Can you make a small stand-alone example that we can try out?

Ben Root

Ray Osborn

Materials Science Division

Argonne National Laboratory

Argonne, IL 60439, USA

Phone: +1 (630) 252-9011

Email: ROsborn@…3972…

Ray Osborn:

  OK - it turns out I can reproduce it in a simple

ipython session using ipython --pylab=qt.

I set up an image plot as follows:

import numpy as np

          import matplotlib.pyplot

as plt

          from matplotlib.image

import NonUniformImage

x=y=np.linspace(0,2*np.pi,101)

X,Y=np.meshgrid(x,y)

z=sin(X)*sin(Y)

ax=plt.gca()

          extent =

(x[0],x[-1],y[0],y[-1])

          im = NonUniformImage(ax,

extent=extent, origin=None)

im.set_data(x,y,z)

ax.images.append(im)

ax.set_xlim(x[0],x[-1])

ax.set_ylim(y[0],y[-1])

plt.colorbar(im)

plt.gcf().canvas.draw()

          After that, I try to

change the color scale using:

im.set_clim(0,0.5)

plt.gcf().canvas.draw()

      The colorbar changes scale, but the plot is untouched. Is

that the expected behavior?

Thanks,

Ray

Try, perhaps, after set_clim, to reinstall the data:

im.set_data(x,y,z)

plt.gcf().canvas.draw()
···

=

Jerzy Karczmarczuk

You're exactly right. That does fix it. Unfortunately, it means I have to refactor some of my code because the Pyside slot doesn't currently have access to the original data, but that's not a huge deal.

Thanks,
Ray

···

On Feb 18, 2012, at 4:35 AM, Jerzy Karczmarczuk wrote:

Ray Osborn:

OK - it turns out I can reproduce it in a simple ipython session using ipython --pylab=qt.

I set up an image plot as follows:

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

x=y=np.linspace(0,2*np.pi,101)
X,Y=np.meshgrid(x,y)
z=sin(X)*sin(Y)

ax=plt.gca()
extent = (x[0],x[-1],y[0],y[-1])
im = NonUniformImage(ax, extent=extent, origin=None)
im.set_data(x,y,z)

ax.images.append(im)
ax.set_xlim(x[0],x[-1])
ax.set_ylim(y[0],y[-1])

plt.colorbar(im)

plt.gcf().canvas.draw()

After that, I try to change the color scale using:

im.set_clim(0,0.5)
plt.gcf().canvas.draw()

The colorbar changes scale, but the plot is untouched. Is that the expected behavior?

Thanks,
Ray

Try, perhaps, after set_clim, to reinstall the data:

im.set_data(x,y,z)
plt.gcf().canvas.draw()

=

Jerzy Karczmarczuk

------------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Ray Osborn
Materials Science Division
Argonne National Laboratory
Argonne, IL 60439, USA
Phone: +1 (630) 252-9011
Email: ROsborn@...3972...

As far as I can see, this is a bug of matplolib, although calling a set_data work around this. Can you open a bug report in our github repo?

-JJ

      1. 오후 10:12에 “Ray Osborn” <ROsborn@…83…3972…>님이 작성:
···

You’re exactly right. That does fix it. Unfortunately, it means I have to refactor some of my code because the Pyside slot doesn’t currently have access to the original data, but that’s not a huge deal.

Thanks,

Ray

On Feb 18, 2012, at 4:35 AM, Jerzy Karczmarczuk wrote:

Ray Osborn:

OK - it turns out I can reproduce it in a simple ipython session using ipython --pylab=qt.

I set up an image plot as follows:

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.image import NonUniformImage

x=y=np.linspace(0,2*np.pi,101)

X,Y=np.meshgrid(x,y)

z=sin(X)*sin(Y)

ax=plt.gca()

extent = (x[0],x[-1],y[0],y[-1])

im = NonUniformImage(ax, extent=extent, origin=None)

im.set_data(x,y,z)

ax.images.append(im)

ax.set_xlim(x[0],x[-1])

ax.set_ylim(y[0],y[-1])

plt.colorbar(im)

plt.gcf().canvas.draw()

After that, I try to change the color scale using:

im.set_clim(0,0.5)

plt.gcf().canvas.draw()

The colorbar changes scale, but the plot is untouched. Is that the expected behavior?

Thanks,

Ray

Try, perhaps, after set_clim, to reinstall the data:

im.set_data(x,y,z)

plt.gcf().canvas.draw()

=

Jerzy Karczmarczuk


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ray Osborn

Materials Science Division

Argonne National Laboratory

Argonne, IL 60439, USA

Phone: +1 (630) 252-9011

Email: ROsborn@…3972…


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I think you’re right. Even if there is a work-around, it can’t be right for the colorbar to change without affecting the image. I’ve filed issue #708.

Thanks,

Ray

···

On Feb 19, 2012, at 4:37 AM, Jae-Joon Lee wrote:

As far as I can see, this is a bug of matplolib, although calling a set_data work around this. Can you open a bug report in our github repo?

-JJ

      1. 오후 10:12에 “Ray Osborn” <ROsborn@…3972…>님이 작성:

You’re exactly right. That does fix it. Unfortunately, it means I have to refactor some of my code because the Pyside slot doesn’t currently have access to the original data, but that’s not a huge deal.

Thanks,

Ray

On Feb 18, 2012, at 4:35 AM, Jerzy Karczmarczuk wrote:

Ray Osborn:

OK - it turns out I can reproduce it in a simple ipython session using ipython --pylab=qt.

I set up an image plot as follows:

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.image import NonUniformImage

x=y=np.linspace(0,2*np.pi,101)

X,Y=np.meshgrid(x,y)

z=sin(X)*sin(Y)

ax=plt.gca()

extent = (x[0],x[-1],y[0],y[-1])

im = NonUniformImage(ax, extent=extent, origin=None)

im.set_data(x,y,z)

ax.images.append(im)

ax.set_xlim(x[0],x[-1])

ax.set_ylim(y[0],y[-1])

plt.colorbar(im)

plt.gcf().canvas.draw()

After that, I try to change the color scale using:

im.set_clim(0,0.5)

plt.gcf().canvas.draw()

The colorbar changes scale, but the plot is untouched. Is that the expected behavior?

Thanks,

Ray

Try, perhaps, after set_clim, to reinstall the data:

im.set_data(x,y,z)

plt.gcf().canvas.draw()

=

Jerzy Karczmarczuk


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ray Osborn

Materials Science Division

Argonne National Laboratory

Argonne, IL 60439, USA

Phone: +1 (630) 252-9011

Email: ROsborn@…3972…


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

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ray Osborn

Materials Science Division

Argonne National Laboratory

Argonne, IL 60439, USA

Phone: +1 (630) 252-9011

Email: ROsborn@…3972…