Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
@anntzer

Description

@anntzer

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 thetop axis.
  • In the right column, I then call cla() on thebottom 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().

test

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

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp