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

Uptade fix number of levels with log contour#29137

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

Open
ebarcelosf wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromebarcelosf:issue2
Open
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
27 changes: 21 additions & 6 deletionslib/matplotlib/contour.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -960,13 +960,12 @@
label.set_color(self.labelMappable.to_rgba(cv))
super().changed()

def _autolev(self, N):
def _autolev(self, N, *, using_default):
Copy link
Member

Choose a reason for hiding this comment

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

I think this extra argument is not necessary.

The only place where this is passed it is simply aN is not None (on the input side, but the effect is the same)

So even if the variable is useful, it can be computed internally.

However, even further, the difference betweenLogLocator() andLogLocator(numticks=N) whenN isNone is nothing, therefore you can just pass it as a kwarg.

Haven't fully thought through the last portion (adjustments if levels are still insufficient) and if there may need to be at least aif N is not None in there potentially, but not sure yet.

"""
Select contour levels to span the data.

The target number of levels, *N*, is used only when the
scale is notlog anddefault locator isused.

locator is notset andthe scale islog or the default
locator is used.

Check warning on line 968 in lib/matplotlib/contour.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/contour.py#L967-L968

Added lines #L967 - L968 were not covered by tests
We need two more levels for filled contours than for
line contours, because for the latter we need to specify
the lower and upper boundary of each range. For example,
Expand All@@ -976,7 +975,12 @@
"""
if self.locator is None:
if self.logscale:
self.locator = ticker.LogLocator()
if using_default:
# Let log locator choose instead of using hard coded value
# set in self._process_contour_level_args()
self.locator = ticker.LogLocator()
else:
self.locator = ticker.LogLocator(numticks=N)
else:
self.locator = ticker.MaxNLocator(N + 1, min_n_ticks=1)

Expand All@@ -993,14 +997,25 @@
i0 = under[-1] if len(under) else 0
over = np.nonzero(lev > self.zmax)[0]
i1 = over[0] + 1 if len(over) else len(lev)

if self.extend in ('min', 'both'):
i0 += 1
if self.extend in ('max', 'both'):
i1 -= 1

# Ensure at least 3 levels and handle log scale specifically
if i1 - i0 < 3:
i0, i1 = 0, len(lev)

# Handle log scale adjustments if levels are still insufficient
if self.logscale and len(lev) < N:
self.locator = ticker.LogLocator(numticks=N+1)
lev = self.locator.tick_values(self.zmin, self.zmax)
under = np.nonzero(lev < self.zmin)[0]
i0 = under[-1] if len(under) else 0
over = np.nonzero(lev > self.zmax)[0]

Check warning on line 1016 in lib/matplotlib/contour.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/contour.py#L1016

Added line #L1016 was not covered by tests
i1 = over[0] + 1 if len(over) else len(lev)

return lev[i0:i1]

def _process_contour_level_args(self, args, z_dtype):
Expand All@@ -1020,7 +1035,7 @@
else:
levels_arg = self.levels
if isinstance(levels_arg, Integral):
self.levels = self._autolev(levels_arg)
self.levels = self._autolev(levels_arg, using_default=self.levels is None)
else:
self.levels = np.asarray(levels_arg, np.float64)
if self.filled and len(self.levels) < 2:
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp