You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Match zdata cursor display scalling with colorbar ? #5409
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.
importmatplotlib.pyplotaspltfrommpl_toolkits.axes_grid1importmake_axes_locatablefrommatplotlib.tickerimportFuncFormatterimportnumpyasnp# Source dataData=np.array(((1.0, 2.0), (3.0, 4.0))) # Data in µmDisplayUnitFactor=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(lambdaz, pos: '{0:g}'.format(z*DisplayUnitFactor))
cbar=plt.colorbar(plot, cax=cbcax, format=cbformat)
plt.show()
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.
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.
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?
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.
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.
Activity
tacaswell commentedon Nov 5, 2015
I don't quite understand what you mean. Can you provide a snippet of code which demonstrates the problem?
JGoutin commentedon Nov 6, 2015
Sorry if I am unclear.
Here is a snippet :
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 commentedon Nov 6, 2015
Why not just scale your data in
matshowinstead of doing it in the colorbar tick formatter?WeatherGod commentedon Nov 6, 2015
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 notifications@github.com
wrote:
efiring commentedon Nov 6, 2015
You are right, this is a reasonable idea, and it looks easy enough for the use case here.
In backend_bases:
One can try to find a
a.colorbar; if it exists and is callable, then use it in place ofa.format_cursor_data.It might also be good to allow an axes to have an
fmt_zdataattribute, likefmt_xdataandfmt_ydatafor 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 commentedon 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 genericArtistmethod. It could be overridden in a color-mapped artist when a colorbar is assigned to it.tacaswell commentedon Nov 6, 2015
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 notifications@github.com wrote:
efiring commentedon Nov 6, 2015
On 2015/11/06 9:40 AM, Thomas A Caswell wrote:
Yes. Colorbar.colorbar_factory attaches the
colorbarattribute to themappable.
JGoutin commentedon Nov 6, 2015
Why not. But my knowledge on mpl low level working is very poor.
I tried to do this, but
a.colorbaris not callable (With my snippet, in any case).efiring commentedon Nov 6, 2015
Oops! I meant to say that one looks for a callable
a.colorbar.formatter.JGoutin commentedon Nov 6, 2015
Work good with this. I created a pull request : #5425.