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 polar aspect#30207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionscheck_version.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
import sys
import os

print(f"--- Python Version Check ---")

Check failure on line 4 in check_version.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶f-string without any placeholdersRaw Output:message:"f-string without any placeholders" location:{path:"/home/runner/work/matplotlib/matplotlib/check_version.py" range:{start:{line:4 column:7} end:{line:4 column:38}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F541" url:"https://docs.astral.sh/ruff/rules/f-string-missing-placeholders"} suggestions:{range:{start:{line:4 column:7} end:{line:4 column:38}} text:"\"--- Python Version Check ---\""}
print(f"Executable: {sys.executable}")
print(f"Version: {sys.version}")
print(f"Current Directory: {os.getcwd()}")

Check failure on line 7 in check_version.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶No newline at end of fileRaw Output:message:"No newline at end of file" location:{path:"/home/runner/work/matplotlib/matplotlib/check_version.py" range:{start:{line:7 column:44} end:{line:7 column:44}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W292" url:"https://docs.astral.sh/ruff/rules/missing-newline-at-end-of-file"} suggestions:{range:{start:{line:7 column:44} end:{line:7 column:44}} text:"\n"}

Check failure on line 7 in check_version.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Trailing whitespaceRaw Output:message:"Trailing whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/check_version.py" range:{start:{line:7 column:43} end:{line:7 column:44}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"W291" url:"https://docs.astral.sh/ruff/rules/trailing-whitespace"} suggestions:{range:{start:{line:7 column:43} end:{line:7 column:44}}}
Binary file addeddoc/_static/polaraxes_correction.png
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 43 additions & 1 deletionlib/matplotlib/projections/polar.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
import math
import types

import numpy as np # Ensure numpy is imported for np.isclose

Check failure on line 4 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Insert at least two spaces before an inline commentRaw Output:message:"Insert at least two spaces before an inline comment" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:4 column:19} end:{line:4 column:20}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E261" url:"https://docs.astral.sh/ruff/rules/too-few-spaces-before-inline-comment"} suggestions:{range:{start:{line:4 column:19} end:{line:4 column:20}} text:" "}

import numpy as np

Check failure on line 6 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Redefinition of unused `np` from line 4Raw Output:message:"Redefinition of unused `np` from line 4" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:6 column:17} end:{line:6 column:19}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F811" url:"https://docs.astral.sh/ruff/rules/redefined-while-unused"} suggestions:{range:{start:{line:6 column:1} end:{line:7 column:1}}}

import matplotlib as mpl
from matplotlib import _api, cbook
Expand All@@ -13,9 +15,9 @@
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms
from matplotlib.spines import Spine

from matplotlib.ticker import FixedLocator, AutoLocator

class PolarTransform(mtransforms.Transform):

Check failure on line 20 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Expected 2 blank lines, found 1Raw Output:message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:20 column:1} end:{line:20 column:6}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:19 column:1} end:{line:20 column:1}} text:"\n\n"}
r"""
The base polar transform.

Expand DownExpand Up@@ -167,6 +169,12 @@
if self._invalid:
limits_scaled = self._limits.transformed(self._scale_transform)
yscale = limits_scaled.ymax - limits_scaled.ymin
if np.isclose(yscale, 0): # Use isclose for float comparison

Check failure on line 172 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Insert at least two spaces before an inline commentRaw Output:message:"Insert at least two spaces before an inline comment" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:172 column:38} end:{line:172 column:39}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E261" url:"https://docs.astral.sh/ruff/rules/too-few-spaces-before-inline-comment"} suggestions:{range:{start:{line:172 column:38} end:{line:172 column:39}} text:" "}
# This case might occur if rmin and rmax are identical,
# or if limits somehow make yscale effectively zero.
# Avoid division by zero or extreme scaling.
# Defaulting to 1 is a fallback; ideally, yscale reflects a valid data range.

Check failure on line 176 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Line too long (93 > 88)Raw Output:message:"Line too long (93 > 88)" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:176 column:89} end:{line:176 column:94}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E501" url:"https://docs.astral.sh/ruff/rules/line-too-long"}
yscale = 1

Check warning on line 177 in lib/matplotlib/projections/polar.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/projections/polar.py#L177

Added line #L177 was not covered by tests
affine = mtransforms.Affine2D() \
.scale(0.5 / yscale) \
.translate(0.5, 0.5)
Expand DownExpand Up@@ -818,6 +826,12 @@
self.yaxis = RadialAxis(self, clear=False)
self.spines['polar'].register_axis(self.yaxis)

# PATCH START
locator = self.xaxis.get_major_locator()
if isinstance(locator, FixedLocator) and len(locator.locs) == 0:
self.xaxis.set_major_locator(AutoLocator())

Check warning on line 832 in lib/matplotlib/projections/polar.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/projections/polar.py#L832

Added line #L832 was not covered by tests
# PATCH END

def _set_lim_and_transforms(self):
# A view limit where the minimum radius can be locked if the user
# specifies an alternate origin.
Expand DownExpand Up@@ -1250,8 +1264,36 @@
def set_rscale(self, *args, **kwargs):
return Axes.set_yscale(self, *args, **kwargs)

# Override set_yticks to ensure our specialized rticks logic is called
def set_yticks(self, ticks, labels=None, minor=False, **kwargs):
# Forward to set_rticks, which contains the clamping logic
# and calls super().set_yticks() itself.
return self.set_rticks(ticks, labels=labels, minor=minor, **kwargs)

def set_rticks(self, *args, **kwargs):
# The first arg is 'ticks'. If called from set_yticks, this is correct.
# If called as ax.set_rticks(radii_list), args[0] is radii_list.
# We need to pass all args and kwargs to Axes.set_yticks.
# The actual setting of yticks (which triggers autoscale) happens here:
result = Axes.set_yticks(self, *args, **kwargs)

# If autoscaling (due to clearing ticks) resulted in rmin > intended origin, clamp rmin.

Check failure on line 1280 in lib/matplotlib/projections/polar.py

View workflow job for this annotation

GitHub Actions/ ruff

[rdjson] reported by reviewdog 🐶Line too long (96 > 88)Raw Output:message:"Line too long (96 > 88)" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/projections/polar.py" range:{start:{line:1280 column:89} end:{line:1280 column:97}}} source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E501" url:"https://docs.astral.sh/ruff/rules/line-too-long"}
# The intended r_origin is 0, unless explicitly set by user via set_rorigin().
# self._originViewLim.locked_y0 stores the value from set_rorigin().
intended_rorigin = self._originViewLim.locked_y0
if intended_rorigin is None:
intended_rorigin = 0.0 # Default r-origin for polar plots

if self.viewLim.y0 > intended_rorigin and not self.yaxis_inverted():
self.viewLim.y0 = intended_rorigin
elif self.viewLim.y1 < intended_rorigin and self.yaxis_inverted():
# Handle inverted r-axis case
self.viewLim.y1 = intended_rorigin

Check warning on line 1291 in lib/matplotlib/projections/polar.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/projections/polar.py#L1291

Added line #L1291 was not covered by tests

# Ensure _originViewLim (which is a LockableBbox(viewLim)) is also updated if not locked.
# This should happen automatically if locked_y0 is None.
# If locked_y0 is not None, viewLim.y0 should already match intended_rorigin due to LockableBbox behavior.

self.yaxis.set_major_locator(
self.RadialLocator(self.yaxis.get_major_locator(), self))
return result
Expand Down
1 change: 1 addition & 0 deletionslib/matplotlib/projections/polar.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -169,6 +169,7 @@
def get_rlabel_position(self) -> float: ...
def set_rlabel_position(self, value: float) -> None: ...
def set_rscale(self, *args, **kwargs) -> None: ...
def set_yticks(self, *args, **kwargs) -> None: ...

Check warning on line 172 in lib/matplotlib/projections/polar.pyi

View workflow job for this annotation

GitHub Actions/ mypy

[mypy] reported by reviewdog 🐶 def set_yticks(self, *args: Any, **kwargs: Any) -> NoneRaw Output:lib/matplotlib/projections/polar.pyi:172: note: def set_yticks(self, *args: Any, **kwargs: Any) -> None

Check warning on line 172 in lib/matplotlib/projections/polar.pyi

View workflow job for this annotation

GitHub Actions/ mypy

[mypy] reported by reviewdog 🐶 Subclass:Raw Output:lib/matplotlib/projections/polar.pyi:172: note: Subclass:

Check warning on line 172 in lib/matplotlib/projections/polar.pyi

View workflow job for this annotation

GitHub Actions/ mypy

[mypy] reported by reviewdog 🐶 def set_yticks(self, ticks: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], labels: Iterable[str] | None = ..., *, minor: bool = ..., **kwargs: Any) -> list[Tick]Raw Output:lib/matplotlib/projections/polar.pyi:172: note: def set_yticks(self, ticks: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], labels: Iterable[str] | None = ..., *, minor: bool = ..., **kwargs: Any) -> list[Tick]

Check warning on line 172 in lib/matplotlib/projections/polar.pyi

View workflow job for this annotation

GitHub Actions/ mypy

[mypy] reported by reviewdog 🐶 Superclass:Raw Output:lib/matplotlib/projections/polar.pyi:172: note: Superclass:

Check failure on line 172 in lib/matplotlib/projections/polar.pyi

View workflow job for this annotation

GitHub Actions/ mypy

[mypy] reported by reviewdog 🐶Signature of "set_yticks" incompatible with supertype "_AxesBase" [override]Raw Output:lib/matplotlib/projections/polar.pyi:172: error: Signature of "set_yticks" incompatible with supertype "_AxesBase" [override]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry I did not follow the mypy syntax here for the python function it would be
def set_yticks(
self,
ticks: Sequence[float],
labels: Sequence[str] | None = ...,
*,
minor: bool = ...
) -> list[float]: ...

def set_rticks(self, *args, **kwargs) -> None: ...
def set_thetagrids(
self,
Expand Down
24 changes: 24 additions & 0 deletionslib/matplotlib/tests/test_polaraxes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
import numpy as np
import matplotlib.pyplot as plt

D = np.array([[2,.3],[.3,2.5]])

# creating an ellipse)
lam, vec = np.linalg.eigh(D)
theta = np.linspace(-np.pi,np.pi,1001)
xy = np.stack((lam[0]*np.cos(theta), lam[1]*np.sin(theta)), axis=0)
xy = vec.T@xy
radii = np.sqrt(np.sum(xy**2, axis=0))
thetas = np.arctan2(-xy[1],xy[0])

plt.figure()
# with ticks
ax1 = plt.subplot(121,projection='polar')
ax1.plot(thetas, radii)
# without ticks
ax2 = plt.subplot(122, projection='polar')
ax2.plot(thetas, radii)
ax2.set_yticks([])
ax2.set_xticks([])

plt.show()
6 changes: 6 additions & 0 deletionsnative-file.ini
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
[binaries]
c = 'gcc'
cpp = 'g++'
[built-in options]
cpp_args = ['-IC:/msys64/mingw64/include']
cpp_link_args = ['-IC:/msys64/mingw64/lib']
Loading

[8]ページ先頭

©2009-2025 Movatter.jp