colorbar+log+latex

Dear list,

I want to plot colored points using scatter, with the
color of points corresponding to the log of the z value of the points.

the corresponding scatter command is :

scatter(x,y,c=z,norm=colors.LogNorm())

unfortunately, then I then draw a colorbar simply calling

colorbar()

the fonts used for the color bar is no longer in latex mode,
as it was if I use a lin scale in scatter(), i.e., norm=None.

Is it a bug ?

Any solution ?

Thanks,

yves

···

--
                                                 (o o)
--------------------------------------------oOO--(_)--OOo-------
  Dr. Yves Revaz
  Laboratory of Astrophysics EPFL
  Observatoire de Sauverny Tel : ++ 41 22 379 24 28
  51. Ch. des Maillettes Fax : ++ 41 22 379 22 05
  1290 Sauverny e-mail : Yves.Revaz@...2003...
  SWITZERLAND Web : http://www.lunix.ch/revaz/
----------------------------------------------------------------

I'm not sure if the default formatter needs to be changed.
However, you may try

import matplotlib.ticker as ticker
formatter=ticker.LogFormatterMathtext()
colorbar(format=formatter)

which will render colorbar ticklabels with mathtext mode.

Regards,

-JJ

···

On Fri, Apr 16, 2010 at 3:56 AM, Yves Revaz <yves.revaz@...2003...> wrote:

Dear list,

I want to plot colored points using scatter, with the
color of points corresponding to the log of the z value of the points.

the corresponding scatter command is :

scatter(x,y,c=z,norm=colors.LogNorm())

unfortunately, then I then draw a colorbar simply calling

colorbar()

the fonts used for the color bar is no longer in latex mode,
as it was if I use a lin scale in scatter(), i.e., norm=None.

Is it a bug ?

Any solution ?

Thanks,

yves

--
(o o)
--------------------------------------------oOO--(_)--OOo-------
Dr. Yves Revaz
Laboratory of Astrophysics EPFL
Observatoire de Sauverny Tel : ++ 41 22 379 24 28
51. Ch. des Maillettes Fax : ++ 41 22 379 22 05
1290 Sauverny e-mail : Yves.Revaz@...2003...
SWITZERLAND Web : http://www.lunix.ch/revaz/
----------------------------------------------------------------

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ok, great, it works !

However, I do not understand why latex mode is
disabled by default...

Anyway, thanks a lot,

yves

Jae-Joon Lee wrote:

···

I'm not sure if the default formatter needs to be changed.
However, you may try

import matplotlib.ticker as ticker
formatter=ticker.LogFormatterMathtext()
colorbar(format=formatter)

which will render colorbar ticklabels with mathtext mode.

Regards,

-JJ

On Fri, Apr 16, 2010 at 3:56 AM, Yves Revaz <yves.revaz@...2003...> wrote:
  

Dear list,

I want to plot colored points using scatter, with the
color of points corresponding to the log of the z value of the points.

the corresponding scatter command is :

scatter(x,y,c=z,norm=colors.LogNorm())

unfortunately, then I then draw a colorbar simply calling

colorbar()

the fonts used for the color bar is no longer in latex mode,
as it was if I use a lin scale in scatter(), i.e., norm=None.

Is it a bug ?

Any solution ?

Thanks,

yves

--
                                                (o o)
--------------------------------------------oOO--(_)--OOo-------
Dr. Yves Revaz
Laboratory of Astrophysics EPFL
Observatoire de Sauverny Tel : ++ 41 22 379 24 28
51. Ch. des Maillettes Fax : ++ 41 22 379 22 05
1290 Sauverny e-mail : Yves.Revaz@...2003...
SWITZERLAND Web : http://www.lunix.ch/revaz/
----------------------------------------------------------------

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
                                                 (o o)
--------------------------------------------oOO--(_)--OOo-------
  Dr. Yves Revaz
  Laboratory of Astrophysics EPFL
  Observatoire de Sauverny Tel : ++ 41 22 379 24 28
  51. Ch. des Maillettes Fax : ++ 41 22 379 22 05
  1290 Sauverny e-mail : Yves.Revaz@...2003...
  SWITZERLAND Web : http://www.lunix.ch/revaz/
----------------------------------------------------------------

Hi there,
I too want a log scale on the colorbar for an imshow plot. I have tried the solution proposed by Jae-Joon but I cannot get the ticklabels to show. I have tried to dynamically change the matplotlibrc settings in ipython using mpl.rc(‘text’,usetex=True) - where mpl = matplotlib. When I run the script I get a whole series of errors (see in italics below) and the figure doesn’t show.
RuntimeError: Could not obtain dvipng version
Exception in Tkinter callback

Is there another way to get a colorbar with a log scale?

On the same topic of the colorbar, how can I readjust the colors such that it only goes between user-specified values? For example, I have one imshow plot where the values range between 0 and 350. However, I only want to look at the values between 300 and 350.

Any help would be greatly appreciated!

Thanks a lot!
Shrividya

[...]

On the same topic of the colorbar, how can I readjust the colors such
that it only goes between user-specified values? For example, I have one
imshow plot where the values range between 0 and 350. However, I only
want to look at the values between 300 and 350.

z = np.arange(25)
z.shape = 5,5
imshow(z, vmin=10, vmax=20, interpolation='nearest')
colorbar(extend='both')

Does that give the desired result?

Eric

···

On 01/25/2011 06:58 PM, Shrividya Ravi wrote:

Any help would be greatly appreciated!

Thanks a lot!
Shrividya

Eric Firing, on 2011-01-25 19:52, wrote:

[...]
> On the same topic of the colorbar, how can I readjust the colors such
> that it only goes between user-specified values? For example, I have one
> imshow plot where the values range between 0 and 350. However, I only
> want to look at the values between 300 and 350.

z = np.arange(25)
z.shape = 5,5
imshow(z, vmin=10, vmax=20, interpolation='nearest')
colorbar(extend='both')

Does that give the desired result?

Hi Shrividya,

Here's how I interpreted what was being asked, in case that
helps.

Also, Eric, is there a reason we make an outline instead of
just cbar.ax.set_frame_on? - My manual adjustments screw up and
confuse whatever data cbar.outline depends on

x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
collection = plt.scatter(x, y, c=z*350, vmin=0, vmax=350)
cbar = plt.colorbar()
cbar.ax.set_ylim(cbar.norm((300,350)))
cbar.ax.set_xlim(cbar.norm((300,350))) # maintain aspect ratio
cbar.set_ticks(np.linspace(300,350,6))
# didn't see a quick way to fix the outline
cbar.outline.set_visible(False)
cbar.ax.set_frame_on(True)
plt.draw()

best,

···

On 01/25/2011 06:58 PM, Shrividya Ravi wrote:

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

Eric Firing, on 2011-01-25 19:52, wrote:

[...]

On the same topic of the colorbar, how can I readjust the colors such
that it only goes between user-specified values? For example, I have one
imshow plot where the values range between 0 and 350. However, I only
want to look at the values between 300 and 350.

z = np.arange(25)
z.shape = 5,5
imshow(z, vmin=10, vmax=20, interpolation='nearest')
colorbar(extend='both')

Does that give the desired result?

Hi Shrividya,

Here's how I interpreted what was being asked, in case that
helps.

(Your interpretation seems like a very strange thing to want to do, but maybe you are right. The OP can inform us.)

Also, Eric, is there a reason we make an outline instead of
just cbar.ax.set_frame_on? - My manual adjustments screw up and
confuse whatever data cbar.outline depends on

Yes, we need to make our own outline because a colorbar does not have to be a rectangle; it can be pointed at either end or both ends.

Eric

···

On 01/25/2011 08:51 PM, Paul Ivanov wrote:

On 01/25/2011 06:58 PM, Shrividya Ravi wrote:

x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
collection = plt.scatter(x, y, c=z*350, vmin=0, vmax=350)
cbar = plt.colorbar()
cbar.ax.set_ylim(cbar.norm((300,350)))
cbar.ax.set_xlim(cbar.norm((300,350))) # maintain aspect ratio
cbar.set_ticks(np.linspace(300,350,6))
# didn't see a quick way to fix the outline
cbar.outline.set_visible(False)
cbar.ax.set_frame_on(True)
plt.draw()

best,

Hi All,
Thanks a bunch for your help!
Eric: your suggestion works brilliantly ( I didn’t use the interpolation kwarg though because I like the ‘smudged’ look). Paul: thanks for your suggestions but I get errors when trying to execute > cbar.set_ticks(np.linspace(300,350,6)). The c.bar.set_ticks option doesn’t seem to exist…

All I now need to figure out is how to get the log scale ticklabels to show for a different imshow plot…

cheers!
Shrividya