FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Interesting things happen when calling cla() on shared axes with log scales · Issue #12819 · matplotlib/matplotlib · GitHub

Repository navigation

Interesting things happen when calling cla() on shared axes with log scales #12819

Description

In the plot below, each axes is yaxis-shared with the axes in the same column.
In each case, I'll start by setting the top yaxis to use a log-base-2 scale.

  • In the left column, I then call cla() on the top axis.
  • In the right column, I then call cla() on the bottom axis.

In every case, the top-left text indicates the scale and formatter used by that axis before the call to cla(), the top-right text indicates the scale and formatter used after the call to cla().

In column 1, the call to cla() on the top axis reset both the scale to linear and the formatter to the default formatter. On the bottom axis, the scale was not reset, but the formatter was.
In column 2, the call to cla() on the bottom axis reset the formatter to the default formatter, but did set the scale to log10(!). The top axis had its scale kept and its formatter reset (similarly to column 1 bottom).

I'm not sure what the correct behavior should be but it's likely not the current one.

Script:

from pylab import *

mem = {}

def remember_scale(ax, title_loc):
    scale = ax.yaxis._scale
    fmt = type(ax.yaxis.get_major_formatter()).__name__
    if scale.name == "linear":
        mem[ax, title_loc] = f"linear\n{fmt}"
    elif scale.name == "log":
        mem[ax, title_loc] = f"log{scale.base}\n{fmt}"
    else:
        mem[ax, title_loc] = "oops"

fig, axs = plt.subplots(2, 2, sharey="col")

axs[0, 0].set_yscale("log", basey=2)
remember_scale(axs[0, 0], "left")
remember_scale(axs[1, 0], "left")
axs[0, 0].cla()
remember_scale(axs[0, 0], "right")
remember_scale(axs[1, 0], "right")

axs[0, 1].set_yscale("log", basey=2)
remember_scale(axs[0, 1], "left")
remember_scale(axs[1, 1], "left")
axs[1, 1].cla()
remember_scale(axs[0, 1], "right")
remember_scale(axs[1, 1], "right")

for (ax, title_loc), scale in mem.items():
    ax.set_title(scale, loc=title_loc)

plt.show()

Noted while reviewing #12818 (digging into #12818 (comment)).

mpl 3.0.2 / Py3.7 / Arch Linux

Activity

  1. github-actions commented on May 22, 2023

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  2. anntzer commented on May 22, 2023

    ContributorAuthor

    For reference purposes this is now spelled

    from pylab import *
    
    mem = {}
    
    def remember_scale(ax, title_loc):
        scale = ax.yaxis._scale
        fmt = type(ax.yaxis.get_major_formatter()).__name__
        if scale.name == "linear":
            mem[ax, title_loc] = f"linear\n{fmt}"
        elif scale.name == "log":
            mem[ax, title_loc] = f"log{scale.base}\n{fmt}"
        else:
            mem[ax, title_loc] = "oops"
    
    fig, axs = plt.subplots(2, 2, sharey="col")
    
    axs[0, 0].set_yscale("log", base=2)
    remember_scale(axs[0, 0], "left")
    remember_scale(axs[1, 0], "left")
    axs[0, 0].cla()
    remember_scale(axs[0, 0], "right")
    remember_scale(axs[1, 0], "right")
    
    axs[0, 1].set_yscale("log", base=2)
    remember_scale(axs[0, 1], "left")
    remember_scale(axs[1, 1], "left")
    axs[1, 1].cla()
    remember_scale(axs[0, 1], "right")
    remember_scale(axs[1, 1], "right")
    
    for (ax, title_loc), scale in mem.items():
        ax.set_title(scale, loc=title_loc)
    
    plt.show()

    (basey renamed to base).

    A small improvement: the bottom left axes now uses log2, not log10.
    The other issues are still present.

  3. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on May 22, 2023
  4. anntzer commented on Sep 24, 2024

    ContributorAuthor

    Superseded by #23503 (looks like I keep rediscovering the issue...)

  5. added and removed
    keepItems to be ignored by the “Stale” Github Action
    on Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL