Skip to content

Commit dbd5f4f

Browse files
authored
Merge branch 'matplotlib:main' into logo_guide
2 parents 55e58e9 + 56c18a4 commit dbd5f4f

File tree

32 files changed

+262
-170
lines changed

32 files changed

+262
-170
lines changed

ci/mypy-stubtest-allowlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ matplotlib\.figure\.FigureBase\.get_figure
4949

5050
# getitem method only exists for 3.10 deprecation backcompatability
5151
matplotlib\.inset\.InsetIndicator\.__getitem__
52+
53+
# only defined in stubs; not present at runtime
54+
matplotlib\.animation\.EventSourceProtocol
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
In-place modifications of colormaps
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Colormaps are planned to become immutable in the long term.
4+
5+
As a first step, in-place modifications of colormaps are now pending-deprecated.
6+
This affects the following methods of `.Colormap`:
7+
8+
- `.Colormap.set_bad` - use ``cmap.with_extremes(bad=...)`` instead
9+
- `.Colormap.set_under` - use ``cmap.with_extremes(under=...)`` instead
10+
- `.Colormap.set_over` - use ``cmap.with_extremes(over=...)`` instead
11+
- `.Colormap.set_extremes` - use ``cmap.with_extremes(...)`` instead
12+
13+
Use the respective `.Colormap.with_extremes` and appropriate keyword arguments
14+
instead which returns a copy of the colormap (available since matplotlib 3.4).
15+
Alternatively, if you create the colormap yourself, you can also pass the
16+
respective arguments to the constructor (available since matplotlib 3.11).

doc/release/next_whats_new/scroll_to_zoom.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Zooming using mouse wheel
22
~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
``Ctrl+MouseWheel`` can be used to zoom in the plot windows.
5+
Additionally, ``x+MouseWheel`` zooms only the x-axis and ``y+MouseWheel`` zooms only the y-axis.
56

6-
The zoom focusses on the mouse pointer, and keeps the aspect ratio of the axes.
7+
The zoom focusses on the mouse pointer. With ``Ctrl``, the axes aspect ratio is kept; with ``x`` or ``y``, only the respective axis is scaled.
78

89
Zooming is currently only supported on rectilinear Axes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
``violin_stats`` simpler *method* parameter
2+
-------------------------------------------
3+
4+
The *method* parameter of `~.cbook.violin_stats` may now be specified as tuple of
5+
strings, and has a new default ``("GaussianKDE", "scott")``. Calling
6+
`~.cbook.violin_stats` followed by `~.Axes.violin` is therefore now equivalent to
7+
calling `~.Axes.violinplot`.
8+
9+
.. plot::
10+
:include-source: true
11+
:alt: Example showing violin_stats followed by violin gives the same result as violinplot
12+
13+
import matplotlib.pyplot as plt
14+
from matplotlib.cbook import violin_stats
15+
import numpy as np
16+
17+
rng = np.random.default_rng(19680801)
18+
data = rng.normal(size=(10, 3))
19+
20+
fig, (ax1, ax2) = plt.subplots(ncols=2, layout='constrained', figsize=(6.4, 3.5))
21+
22+
# Create the violin plot in one step
23+
ax1.violinplot(data)
24+
ax1.set_title('One Step')
25+
26+
# Process the data and then create the violin plot
27+
vstats = violin_stats(data)
28+
ax2.violin(vstats)
29+
ax2.set_title('Two Steps')
30+
31+
plt.show()

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencies:
5353
- sphinxcontrib-video>=0.2.1
5454
- pikepdf
5555
# testing
56-
- black<24
56+
- black<26
5757
- coverage
5858
- gtk4
5959
- ipykernel

galleries/examples/shapes_and_collections/donut.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@
1515

1616

1717
def wise(v):
18-
if v == 1:
19-
return "CCW"
20-
else:
21-
return "CW"
18+
return {+1: "CCW", -1: "CW"}[v]
2219

2320

2421
def make_circle(r):
2522
t = np.arange(0, np.pi * 2.0, 0.01)
26-
t = t.reshape((len(t), 1))
2723
x = r * np.cos(t)
2824
y = r * np.sin(t)
29-
return np.hstack((x, y))
25+
return np.column_stack((x, y))
3026

31-
Path = mpath.Path
3227

3328
fig, ax = plt.subplots()
3429

3530
inside_vertices = make_circle(0.5)
3631
outside_vertices = make_circle(1.0)
37-
codes = np.ones(
38-
len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
32+
codes = np.full(len(inside_vertices), mpath.Path.LINETO)
3933
codes[0] = mpath.Path.MOVETO
4034

4135
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):
@@ -44,23 +38,20 @@ def make_circle(r):
4438
vertices = np.concatenate((outside_vertices[::outside],
4539
inside_vertices[::inside]))
4640
# Shift the path
47-
vertices[:, 0] += i * 2.5
41+
vertices += (i * 2.5, 0)
4842
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
4943
# beginning of each subpath
5044
all_codes = np.concatenate((codes, codes))
5145
# Create the Path object
5246
path = mpath.Path(vertices, all_codes)
53-
# Add plot it
47+
# And plot it
5448
patch = mpatches.PathPatch(path, facecolor='#885500', edgecolor='black')
5549
ax.add_patch(patch)
5650

5751
ax.annotate(f"Outside {wise(outside)},\nInside {wise(inside)}",
5852
(i * 2.5, -1.5), va="top", ha="center")
5953

60-
ax.set_xlim(-2, 10)
61-
ax.set_ylim(-3, 2)
62-
ax.set_title('Mmm, donuts!')
63-
ax.set_aspect(1.0)
54+
ax.set(xlim=(-2, 10), ylim=(-3, 2), aspect=1, title="Mmm, donuts!")
6455
plt.show()
6556

6657
# %%

galleries/users_explain/text/mathtext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,4 @@
370370
# If a particular symbol does not have a name (as is true of many of the more
371371
# obscure symbols in the STIX fonts), Unicode characters can also be used::
372372
#
373-
# r'$\u23ce$'
373+
# '$\u23ce$'

lib/matplotlib/animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ class Animation:
861861
fig : `~matplotlib.figure.Figure`
862862
The figure object used to get needed events, such as draw or resize.
863863
864-
event_source : object, optional
864+
event_source : object
865865
A class that can run a callback when desired events
866866
are generated, as well as be stopped and started.
867867
@@ -877,7 +877,7 @@ class Animation:
877877
FuncAnimation, ArtistAnimation
878878
"""
879879

880-
def __init__(self, fig, event_source=None, blit=False):
880+
def __init__(self, fig, event_source, blit=False):
881881
self._draw_was_started = False
882882

883883
self._fig = fig

lib/matplotlib/animation.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from matplotlib.artist import Artist
66
from matplotlib.backend_bases import TimerBase
77
from matplotlib.figure import Figure
88

9-
from typing import Any
9+
from typing import Any, Protocol
1010

1111
subprocess_creation_flags: int
1212

@@ -152,11 +152,17 @@ class HTMLWriter(FileMovieWriter):
152152
def grab_frame(self, **savefig_kwargs): ...
153153
def finish(self) -> None: ...
154154

155+
class EventSourceProtocol(Protocol):
156+
def add_callback(self, func: Callable): ...
157+
def remove_callback(self, func: Callable): ...
158+
def start(self): ...
159+
def stop(self): ...
160+
155161
class Animation:
156162
frame_seq: Iterable[Artist]
157-
event_source: Any
163+
event_source: EventSourceProtocol | None # TODO: We should remove None
158164
def __init__(
159-
self, fig: Figure, event_source: Any | None = ..., blit: bool = ...
165+
self, fig: Figure, event_source: EventSourceProtocol, blit: bool = ...
160166
) -> None: ...
161167
def __del__(self) -> None: ...
162168
def save(

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9006,6 +9006,8 @@ def violin(self, vpstats, positions=None, vert=None,
90069006
--------
90079007
violinplot :
90089008
Draw a violin plot from data instead of pre-computed statistics.
9009+
.cbook.violin_stats:
9010+
Calculate a *vpstats* dictionary from data, suitable for passing to violin.
90099011
"""
90109012

90119013
# Statistical quantities to be plotted on the violins

0 commit comments

Comments
 (0)