Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Match zdata cursor display scalling with colorbar ? #5409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JGoutin opened this issue Nov 5, 2015 · 11 comments
Closed

Match zdata cursor display scalling with colorbar ? #5409

JGoutin opened this issue Nov 5, 2015 · 11 comments

Comments

@JGoutin
Copy link
Contributor

JGoutin commented Nov 5, 2015

Hello,

With Matplotlib 1.5.0, zdata to the cursor is displayed in the status bar. It is a very good new feature.
But, this zdata is the base data value, and this don't match if a scalling is used with the colorbar.

Is it possible to scale this displayed zdata like the colorbar ? I din't found an existing function for rescale this zdata.

I think the better solution should be to default use the scaling used on the colorbar.

Thanks.

@tacaswell
Copy link
Member

I don't quite understand what you mean. Can you provide a snippet of code which demonstrates the problem?

@JGoutin
Copy link
Contributor Author

JGoutin commented Nov 6, 2015

Sorry if I am unclear.

Here is a snippet :

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.ticker import FuncFormatter
import numpy as np

# Source data
Data = np.array(((1.0, 2.0), (3.0, 4.0)))  # Data in µm
DisplayUnitFactor = 1000  # Display unit is nm

# A plot with Data (µm)
plot = plt.matshow(Data)

# Colorbar with Z scalled to unit (nm)
cbcax = make_axes_locatable(plt.gca()).append_axes("right", "10%", pad="1%")
cbformat = FuncFormatter(lambda z, pos: '{0:g}'.format(z * DisplayUnitFactor))
cbar = plt.colorbar(plot, cax=cbcax, format=cbformat)

plt.show()

example
In Statusbar, Z is still in µm even if my colorbar is in nm.

Ideally, FuncFormatter from the colorbar may be applied on the statusbar Z display also.

@efiring
Copy link
Member

efiring commented Nov 6, 2015

Why not just scale your data in matshow instead of doing it in the colorbar tick formatter?

@WeatherGod
Copy link
Member

Isn't that besides the point? Don't we already obtain the axis formatters
for the x and y coordinates? I think it would make sense to use the
colorbar's formatter if it is available.

On Fri, Nov 6, 2015 at 1:14 PM, Eric Firing [email protected]
wrote:

Why not just scale your data in matshow instead of doing it in the
colorbar tick formatter?


Reply to this email directly or view it on GitHub
#5409 (comment)
.

@efiring
Copy link
Member

efiring commented Nov 6, 2015

You are right, this is a reasonable idea, and it looks easy enough for the use case here.
In backend_bases:

   2839                     a = max(enumerate(artists), key=lambda x: x[1].zorder)[1]
   2840                     if a is not event.inaxes.patch:
   2841                         data = a.get_cursor_data(event)
   2842                         if data is not None:
   2843                             s += ' [%s]' % a.format_cursor_data(data)
   2844

One can try to find a a.colorbar; if it exists and is callable, then use it in place of a.format_cursor_data.
It might also be good to allow an axes to have an fmt_zdata attribute, like fmt_xdata and fmt_ydata for setting an alternative formatter. One might not always want the formatting for the cursor display be the same as for the colorbar ticks.
@JGoutin would you like to generate a pull request along these lines? Or at least for the first part?

@efiring
Copy link
Member

efiring commented Nov 6, 2015

Side comment: it would be nice not to have so much logic executed inside mouse_move; maybe some of it can be factored out. format_cursor_data() is a generic Artist method. It could be overridden in a color-mapped artist when a colorbar is assigned to it.

@tacaswell
Copy link
Member

Do the color mappables know what color bar they are associated with?

This seems like a very deep coupling that I am not sure we want.

In any case, the logic for this mapping should live in the artists, not the
axes.

On Fri, Nov 6, 2015, 13:32 Benjamin Root [email protected] wrote:

Isn't that besides the point? Don't we already obtain the axis formatters
for the x and y coordinates? I think it would make sense to use the
colorbar's formatter if it is available.

On Fri, Nov 6, 2015 at 1:14 PM, Eric Firing [email protected]
wrote:

Why not just scale your data in matshow instead of doing it in the
colorbar tick formatter?


Reply to this email directly or view it on GitHub
<
#5409 (comment)

.


Reply to this email directly or view it on GitHub
#5409 (comment)
.

@efiring
Copy link
Member

efiring commented Nov 6, 2015

On 2015/11/06 9:40 AM, Thomas A Caswell wrote:

Do the color mappables know what color bar they are associated with?

Yes. Colorbar.colorbar_factory attaches the colorbar attribute to the
mappable.

@JGoutin
Copy link
Contributor Author

JGoutin commented Nov 6, 2015

would you like to generate a pull request along these lines? Or at least for the first part?

Why not. But my knowledge on mpl low level working is very poor.

One can try to find a a.colorbar; if it exists and is callable, then use it in place of a.format_cursor_data.

I tried to do this, but a.colorbar is not callable (With my snippet, in any case).

@efiring
Copy link
Member

efiring commented Nov 6, 2015

Oops! I meant to say that one looks for a callable a.colorbar.formatter.

@JGoutin
Copy link
Contributor Author

JGoutin commented Nov 6, 2015

Work good with this. I created a pull request : #5425.

@JGoutin JGoutin closed this as completed Nov 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants