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

Fix limits if one axis scale is 'log' #27085

Closed as not planned
Closed as not planned
@swagner-astro

Description

@swagner-astro

Problem

I am plotting my data (x,y) and want to show the x-axis in logscale. Because there are some negative values in x, the log10 can not be computed for all. This results in nans which are simply omitted when plotting (and this is what I want) but the y-axis limits are not updated for these missing values. It would be helpful to automatically set new axis limits if there are nans in the data.

Example:

import numpy as npimport matplotlib.pyplot as pltx = np.arange(-10, 11, 1) plt.plot(x,x, marker='d')

Screen Shot 2023-10-11 at 20 40 14

and when I add the log scale on the x-axis, the negative values are omitted but the y-axis is not updated (even though I set nonpositive to 'clip' -- so maybe this is a bug?)

x = np.arange(-10, 11, 1) plt.plot(x,x, marker='d')plt.xscale('log', nonpositive='clip')

Screen Shot 2023-10-13 at 15 53 02

In order to manually setylimone would need to know the exact values of the data, so I suggest this could be adjusted automatically.

Setup

Python 3.8.8
Matplotlib 3.7.1
Numpy 1.24.3
notebook 6.2.0 (executing and plotting in jupyter notebook)
on macOS 12.6.2 (Monterey)

Proposed solution

Idea:
If the xscale is set to 'log' and there are negative values in x, take the position of minimum of x < 0 and set y value at that position as new limit (ideally with the same margin as in the rest of the figure):

assuming self is the axis

margin = 0.1if len(x[x<0]) !=0 and self.get_xscale=='log':    ii_x_g0 = np.min(np.where(x>0))    self.set_ylim(bottom = y[ii_x_g0] - y[ii_x_g0] * margin)

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