Skip to content

Match zdata cursor display scalling with colorbar ? #5409

Closed

Description

@JGoutin

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.

Activity

  1. tacaswell commented on Nov 5, 2015

    @tacaswell
    Member

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

  2. JGoutin commented on Nov 6, 2015

    @JGoutin
    ContributorAuthor

    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.

  3. efiring commented on Nov 6, 2015

    @efiring
    Member

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

  4. WeatherGod commented on Nov 6, 2015

    @WeatherGod
    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 notifications@github.com
    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)
    .

  5. efiring commented on Nov 6, 2015

    @efiring
    Member

    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?

  6. efiring commented on Nov 6, 2015

    @efiring
    Member

    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.

  7. tacaswell commented on Nov 6, 2015

    @tacaswell
    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 notifications@github.com 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 notifications@github.com
    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)
    .

  8. efiring commented on Nov 6, 2015

    @efiring
    Member

    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.

  9. JGoutin commented on Nov 6, 2015

    @JGoutin
    ContributorAuthor

    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).

  10. efiring commented on Nov 6, 2015

    @efiring
    Member

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

  11. JGoutin commented on Nov 6, 2015

    @JGoutin
    ContributorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions