Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24f0623

Browse files
author
Estefania Barreto-Ojeda
authored
Merge branch 'matplotlib:main' into issue21761
2 parents 3b834f4 + 632260e commit 24f0623

File tree

8 files changed

+79
-181
lines changed

8 files changed

+79
-181
lines changed

examples/misc/load_converter.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/mplot3d/rotate_axes3d_sgskip.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rotating a 3D plot
44
==================
55
6-
A very simple animation of a rotating 3D plot.
6+
A very simple animation of a rotating 3D plot about all 3 axes.
77
88
See wire3d_animation_demo for another simple example of animating a 3D plot.
99
@@ -17,12 +17,34 @@
1717
fig = plt.figure()
1818
ax = fig.add_subplot(projection='3d')
1919

20-
# load some test data for demonstration and plot a wireframe
21-
X, Y, Z = axes3d.get_test_data(0.1)
22-
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)
20+
# Grab some example data and plot a basic wireframe.
21+
X, Y, Z = axes3d.get_test_data(0.05)
22+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
23+
24+
# Set the axis labels
25+
ax.set_xlabel('x')
26+
ax.set_ylabel('y')
27+
ax.set_zlabel('z')
28+
29+
# Rotate the axes and update
30+
for angle in range(0, 360*4 + 1):
31+
# Normalize the angle to the range [-180, 180] for display
32+
angle_norm = (angle + 180) % 360 - 180
33+
34+
# Cycle through a full rotation of elevation, then azimuth, roll, and all
35+
elev = azim = roll = 0
36+
if angle <= 360:
37+
elev = angle_norm
38+
elif angle <= 360*2:
39+
azim = angle_norm
40+
elif angle <= 360*3:
41+
roll = angle_norm
42+
else:
43+
elev = azim = roll = angle_norm
44+
45+
# Update the axis view and title
46+
ax.view_init(elev, azim, roll)
47+
plt.title('Elevation: %d°, Azimuth: %d°, Roll: %d°' % (elev, azim, roll))
2348

24-
# rotate the axes and update
25-
for angle in range(0, 360):
26-
ax.view_init(30, angle, 0)
2749
plt.draw()
2850
plt.pause(.001)

examples/mplot3d/wire3d_animation_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
==========================
3-
Rotating 3D wireframe plot
4-
==========================
2+
=============================
3+
Animating a 3D wireframe plot
4+
=============================
55
66
A very simple 'animation' of a 3D plot. See also rotate_axes3d_demo.
77

examples/subplots_axes_and_figures/axes_zoom_effect.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,14 @@ def zoom_effect02(ax1, ax2, **kwargs):
109109
return c1, c2, bbox_patch1, bbox_patch2, p
110110

111111

112-
plt.figure(figsize=(5, 5))
113-
ax1 = plt.subplot(221)
114-
ax2 = plt.subplot(212)
115-
ax2.set_xlim(0, 1)
116-
ax2.set_xlim(0, 5)
117-
zoom_effect01(ax1, ax2, 0.2, 0.8)
118-
119-
120-
ax1 = plt.subplot(222)
121-
ax1.set_xlim(2, 3)
122-
ax2.set_xlim(0, 5)
123-
zoom_effect02(ax1, ax2)
112+
axs = plt.figure().subplot_mosaic([
113+
["zoom1", "zoom2"],
114+
["main", "main"],
115+
])
116+
117+
axs["main"].set(xlim=(0, 5))
118+
zoom_effect01(axs["zoom1"], axs["main"], 0.2, 0.8)
119+
axs["zoom2"].set(xlim=(2, 3))
120+
zoom_effect02(axs["zoom2"], axs["main"])
124121

125122
plt.show()

lib/matplotlib/backends/backend_ps.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -838,17 +838,10 @@ class FigureCanvasPS(FigureCanvasBase):
838838
def get_default_filetype(self):
839839
return 'ps'
840840

841-
@_api.delete_parameter("3.5", "args")
842-
def print_ps(self, outfile, *args, **kwargs):
843-
return self._print_ps(outfile, 'ps', **kwargs)
844-
845-
@_api.delete_parameter("3.5", "args")
846-
def print_eps(self, outfile, *args, **kwargs):
847-
return self._print_ps(outfile, 'eps', **kwargs)
848-
849841
@_api.delete_parameter("3.4", "dpi")
842+
@_api.delete_parameter("3.5", "args")
850843
def _print_ps(
851-
self, outfile, format, *,
844+
self, fmt, outfile, *args,
852845
dpi=None, metadata=None, papertype=None, orientation='portrait',
853846
**kwargs):
854847

@@ -885,12 +878,12 @@ def _print_ps(
885878
printer = (self._print_figure_tex
886879
if mpl.rcParams['text.usetex'] else
887880
self._print_figure)
888-
printer(outfile, format, dpi=dpi, dsc_comments=dsc_comments,
881+
printer(fmt, outfile, dpi=dpi, dsc_comments=dsc_comments,
889882
orientation=orientation, papertype=papertype, **kwargs)
890883

891884
@_check_savefig_extra_args
892885
def _print_figure(
893-
self, outfile, format, *,
886+
self, fmt, outfile, *,
894887
dpi, dsc_comments, orientation, papertype,
895888
bbox_inches_restore=None):
896889
"""
@@ -900,7 +893,7 @@ def _print_figure(
900893
all string containing Document Structuring Convention comments,
901894
generated from the *metadata* parameter to `.print_figure`.
902895
"""
903-
is_eps = format == 'eps'
896+
is_eps = fmt == 'eps'
904897
if not (isinstance(outfile, (str, os.PathLike))
905898
or is_writable_file_like(outfile)):
906899
raise ValueError("outfile must be a path or a file-like object")
@@ -1028,7 +1021,7 @@ def print_figure_impl(fh):
10281021

10291022
@_check_savefig_extra_args
10301023
def _print_figure_tex(
1031-
self, outfile, format, *,
1024+
self, fmt, outfile, *,
10321025
dpi, dsc_comments, orientation, papertype,
10331026
bbox_inches_restore=None):
10341027
"""
@@ -1038,7 +1031,7 @@ def _print_figure_tex(
10381031
10391032
The rest of the behavior is as for `._print_figure`.
10401033
"""
1041-
is_eps = format == 'eps'
1034+
is_eps = fmt == 'eps'
10421035

10431036
width, height = self.figure.get_size_inches()
10441037
xo = 0
@@ -1121,6 +1114,9 @@ def _print_figure_tex(
11211114

11221115
_move_path_to_path_or_stream(tmpfile, outfile)
11231116

1117+
print_ps = functools.partialmethod(_print_ps, "ps")
1118+
print_eps = functools.partialmethod(_print_ps, "eps")
1119+
11241120
def draw(self):
11251121
self.figure.draw_without_rendering()
11261122
return super().draw()

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ def __init__(self, bitmap, renderer):
332332

333333
dc, gfx_ctx = self._cache.get(bitmap, (None, None))
334334
if dc is None:
335-
dc = wx.MemoryDC()
336-
dc.SelectObject(bitmap)
335+
dc = wx.MemoryDC(bitmap)
337336
gfx_ctx = wx.GraphicsContext.Create(dc)
338337
gfx_ctx._lastcliprect = None
339338
self._cache[bitmap] = dc, gfx_ctx

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,63 +27,30 @@ def draw(self, drawDC=None):
2727
Render the figure using agg.
2828
"""
2929
FigureCanvasAgg.draw(self)
30-
31-
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
30+
self.bitmap = _rgba_to_wx_bitmap(self.get_renderer().buffer_rgba())
3231
self._isDrawn = True
3332
self.gui_repaint(drawDC=drawDC)
3433

3534
def blit(self, bbox=None):
3635
# docstring inherited
36+
bitmap = _rgba_to_wx_bitmap(self.get_renderer().buffer_rgba())
3737
if bbox is None:
38-
self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
39-
self.gui_repaint()
40-
return
41-
42-
srcBmp = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
43-
srcDC = wx.MemoryDC()
44-
srcDC.SelectObject(srcBmp)
45-
46-
destDC = wx.MemoryDC()
47-
destDC.SelectObject(self.bitmap)
48-
49-
x = int(bbox.x0)
50-
y = int(self.bitmap.GetHeight() - bbox.y1)
51-
destDC.Blit(x, y, int(bbox.width), int(bbox.height), srcDC, x, y)
52-
53-
destDC.SelectObject(wx.NullBitmap)
54-
srcDC.SelectObject(wx.NullBitmap)
38+
self.bitmap = bitmap
39+
else:
40+
srcDC = wx.MemoryDC(bitmap)
41+
destDC = wx.MemoryDC(self.bitmap)
42+
x = int(bbox.x0)
43+
y = int(self.bitmap.GetHeight() - bbox.y1)
44+
destDC.Blit(x, y, int(bbox.width), int(bbox.height), srcDC, x, y)
45+
destDC.SelectObject(wx.NullBitmap)
46+
srcDC.SelectObject(wx.NullBitmap)
5547
self.gui_repaint()
5648

5749

58-
def _convert_agg_to_wx_bitmap(agg, bbox):
59-
"""
60-
Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If
61-
bbox is None, the entire buffer is converted.
62-
Note: agg must be a backend_agg.RendererAgg instance.
63-
"""
64-
if bbox is None:
65-
# agg => rgba buffer -> bitmap
66-
return wx.Bitmap.FromBufferRGBA(int(agg.width), int(agg.height),
67-
agg.buffer_rgba())
68-
else:
69-
# agg => rgba buffer -> bitmap => clipped bitmap
70-
srcBmp = wx.Bitmap.FromBufferRGBA(int(agg.width), int(agg.height),
71-
agg.buffer_rgba())
72-
srcDC = wx.MemoryDC()
73-
srcDC.SelectObject(srcBmp)
74-
75-
destBmp = wx.Bitmap(int(bbox.width), int(bbox.height))
76-
destDC = wx.MemoryDC()
77-
destDC.SelectObject(destBmp)
78-
79-
x = int(bbox.x0)
80-
y = int(int(agg.height) - bbox.y1)
81-
destDC.Blit(0, 0, int(bbox.width), int(bbox.height), srcDC, x, y)
82-
83-
srcDC.SelectObject(wx.NullBitmap)
84-
destDC.SelectObject(wx.NullBitmap)
85-
86-
return destBmp
50+
def _rgba_to_wx_bitmap(rgba):
51+
"""Convert an RGBA buffer to a wx.Bitmap."""
52+
h, w, _ = rgba.shape
53+
return wx.Bitmap.FromBufferRGBA(w, h, rgba)
8754

8855

8956
@_BackendWx.export

lib/mpl_toolkits/axes_grid1/inset_locator.py

Lines changed: 12 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,8 @@ class BboxConnector(Patch):
168168
@staticmethod
169169
def get_bbox_edge_pos(bbox, loc):
170170
"""
171-
Helper function to obtain the location of a corner of a bbox
172-
173-
Parameters
174-
----------
175-
bbox : `matplotlib.transforms.Bbox`
176-
177-
loc : {1, 2, 3, 4}
178-
Corner of *bbox*. Valid values are::
179-
180-
'upper right' : 1,
181-
'upper left' : 2,
182-
'lower left' : 3,
183-
'lower right' : 4
184-
185-
Returns
186-
-------
187-
x, y : float
188-
Coordinates of the corner specified by *loc*.
171+
Return the ``(x, y)`` coordinates of corner *loc* of *bbox*; parameters
172+
behave as documented for the `.BboxConnector` constructor.
189173
"""
190174
x0, y0, x1, y1 = bbox.extents
191175
if loc == 1:
@@ -200,35 +184,9 @@ def get_bbox_edge_pos(bbox, loc):
200184
@staticmethod
201185
def connect_bbox(bbox1, bbox2, loc1, loc2=None):
202186
"""
203-
Helper function to obtain a Path from one bbox to another.
204-
205-
Parameters
206-
----------
207-
bbox1, bbox2 : `matplotlib.transforms.Bbox`
208-
Bounding boxes to connect.
209-
210-
loc1 : {1, 2, 3, 4}
211-
Corner of *bbox1* to use. Valid values are::
212-
213-
'upper right' : 1,
214-
'upper left' : 2,
215-
'lower left' : 3,
216-
'lower right' : 4
217-
218-
loc2 : {1, 2, 3, 4}, optional
219-
Corner of *bbox2* to use. If None, defaults to *loc1*.
220-
Valid values are::
221-
222-
'upper right' : 1,
223-
'upper left' : 2,
224-
'lower left' : 3,
225-
'lower right' : 4
226-
227-
Returns
228-
-------
229-
path : `matplotlib.path.Path`
230-
A line segment from the *loc1* corner of *bbox1* to the *loc2*
231-
corner of *bbox2*.
187+
Construct a `.Path` connecting corner *loc1* of *bbox1* to corner
188+
*loc2* of *bbox2*, where parameters behave as documented as for the
189+
`.BboxConnector` constructor.
232190
"""
233191
if isinstance(bbox1, Rectangle):
234192
bbox1 = TransformedBbox(Bbox.unit(), bbox1.get_transform())
@@ -250,22 +208,15 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs):
250208
bbox1, bbox2 : `matplotlib.transforms.Bbox`
251209
Bounding boxes to connect.
252210
253-
loc1 : {1, 2, 3, 4}
254-
Corner of *bbox1* to draw the line. Valid values are::
211+
loc1, loc2 : {1, 2, 3, 4}
212+
Corner of *bbox1* and *bbox2* to draw the line. Valid values are::
255213
256214
'upper right' : 1,
257215
'upper left' : 2,
258216
'lower left' : 3,
259217
'lower right' : 4
260218
261-
loc2 : {1, 2, 3, 4}, optional
262-
Corner of *bbox2* to draw the line. If None, defaults to *loc1*.
263-
Valid values are::
264-
265-
'upper right' : 1,
266-
'upper left' : 2,
267-
'lower left' : 3,
268-
'lower right' : 4
219+
*loc2* is optional and defaults to *loc1*.
269220
270221
**kwargs
271222
Patch properties for the line drawn. Valid arguments include:
@@ -308,18 +259,10 @@ def __init__(self, bbox1, bbox2, loc1a, loc2a, loc1b, loc2b, **kwargs):
308259
bbox1, bbox2 : `matplotlib.transforms.Bbox`
309260
Bounding boxes to connect.
310261
311-
loc1a, loc2a : {1, 2, 3, 4}
312-
Corners of *bbox1* and *bbox2* to draw the first line.
313-
Valid values are::
314-
315-
'upper right' : 1,
316-
'upper left' : 2,
317-
'lower left' : 3,
318-
'lower right' : 4
319-
320-
loc1b, loc2b : {1, 2, 3, 4}
321-
Corners of *bbox1* and *bbox2* to draw the second line.
322-
Valid values are::
262+
loc1a, loc2a, loc1b, loc2b : {1, 2, 3, 4}
263+
The first line connects corners *loc1a* of *bbox1* and *loc2a* of
264+
*bbox2*; the second line connects corners *loc1b* of *bbox1* and
265+
*loc2b* of *bbox2*. Valid values are::
323266
324267
'upper right' : 1,
325268
'upper left' : 2,

0 commit comments

Comments
 (0)