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

Skip to content

Commit b8ae7bd

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents cb0a64c + 71771ea commit b8ae7bd

5 files changed

Lines changed: 35 additions & 55 deletions

File tree

examples/lines_bars_and_markers/scatter_piecharts.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
This example makes custom 'pie charts' as the markers for a scatter plot.
77
8-
Thanks to Manuel Metz for the example
8+
Thanks to Manuel Metz for the example.
99
"""
1010

1111
import numpy as np
@@ -19,31 +19,26 @@
1919
sizes = np.array([60, 80, 120])
2020

2121
# calculate the points of the first pie marker
22-
#
23-
# these are just the origin (0,0) +
24-
# some points on a circle cos,sin
25-
x = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
26-
y = [0] + np.sin(np.linspace(0, 2 * np.pi * r1, 10)).tolist()
27-
xy1 = np.column_stack([x, y])
22+
# these are just the origin (0,0) + some points on a circle cos,sin
23+
x1 = np.cos(2 * np.pi * np.linspace(0, r1))
24+
y1 = np.sin(2 * np.pi * np.linspace(0, r1))
25+
xy1 = np.row_stack([[0, 0], np.column_stack([x1, y1])])
2826
s1 = np.abs(xy1).max()
2927

30-
x = [0] + np.cos(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
31-
y = [0] + np.sin(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist()
32-
xy2 = np.column_stack([x, y])
28+
x2 = np.cos(2 * np.pi * np.linspace(r1, r2))
29+
y2 = np.sin(2 * np.pi * np.linspace(r1, r2))
30+
xy2 = np.row_stack([[0, 0], np.column_stack([x2, y2])])
3331
s2 = np.abs(xy2).max()
3432

35-
x = [0] + np.cos(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
36-
y = [0] + np.sin(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist()
37-
xy3 = np.column_stack([x, y])
33+
x3 = np.cos(2 * np.pi * np.linspace(r2, 1))
34+
y3 = np.sin(2 * np.pi * np.linspace(r2, 1))
35+
xy3 = np.row_stack([[0, 0], np.column_stack([x3, y3])])
3836
s3 = np.abs(xy3).max()
3937

4038
fig, ax = plt.subplots()
41-
ax.scatter(range(3), range(3), marker=xy1,
42-
s=s1 ** 2 * sizes, facecolor='blue')
43-
ax.scatter(range(3), range(3), marker=xy2,
44-
s=s2 ** 2 * sizes, facecolor='green')
45-
ax.scatter(range(3), range(3), marker=xy3,
46-
s=s3 ** 2 * sizes, facecolor='red')
39+
ax.scatter(range(3), range(3), marker=xy1, s=s1**2 * sizes, facecolor='blue')
40+
ax.scatter(range(3), range(3), marker=xy2, s=s2**2 * sizes, facecolor='green')
41+
ax.scatter(range(3), range(3), marker=xy3, s=s3**2 * sizes, facecolor='red')
4742

4843
plt.show()
4944

examples/misc/agg_buffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
plt.plot([1, 2, 3])
1616

17-
canvas = plt.get_current_fig_manager().canvas
17+
canvas = plt.gcf().canvas
1818

1919
agg = canvas.switch_backends(FigureCanvasAgg)
2020
agg.draw()

lib/matplotlib/hatch.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, hatch, density):
5757
self.num_vertices = 0
5858

5959
def set_vertices_and_codes(self, vertices, codes):
60-
steps = np.linspace(-0.5, 0.5, self.num_lines + 1, True)
60+
steps = np.linspace(-0.5, 0.5, self.num_lines + 1)
6161
vertices[0::2, 0] = 0.0 + steps
6262
vertices[0::2, 1] = 0.0 - steps
6363
vertices[1::2, 0] = 1.0 + steps
@@ -77,7 +77,7 @@ def __init__(self, hatch, density):
7777
self.num_vertices = 0
7878

7979
def set_vertices_and_codes(self, vertices, codes):
80-
steps = np.linspace(-0.5, 0.5, self.num_lines + 1, True)
80+
steps = np.linspace(-0.5, 0.5, self.num_lines + 1)
8181
vertices[0::2, 0] = 0.0 + steps
8282
vertices[0::2, 1] = 1.0 + steps
8383
vertices[1::2, 0] = 1.0 + steps
@@ -111,10 +111,9 @@ def set_vertices_and_codes(self, vertices, codes):
111111
cursor = 0
112112
for row in range(self.num_rows + 1):
113113
if row % 2 == 0:
114-
cols = np.linspace(0.0, 1.0, self.num_rows + 1, True)
114+
cols = np.linspace(0, 1, self.num_rows + 1)
115115
else:
116-
cols = np.linspace(offset / 2.0, 1.0 - offset / 2.0,
117-
self.num_rows, True)
116+
cols = np.linspace(offset / 2, 1 - offset / 2, self.num_rows)
118117
row_pos = row * offset
119118
for col_pos in cols:
120119
vertices[cursor:cursor + shape_size] = (shape_vertices +

lib/matplotlib/legend_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def get_xdata(self, legend, xdescent, ydescent, width, height, fontsize):
168168
numpoints)
169169
xdata_marker = xdata
170170
else:
171-
xdata = np.linspace(-xdescent, -xdescent + width, 2)
171+
xdata = [-xdescent, -xdescent + width]
172172
xdata_marker = [-xdescent + 0.5 * width]
173173
return xdata, xdata_marker
174174

@@ -326,7 +326,7 @@ def create_artists(self, legend, orig_handle,
326326

327327
xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent,
328328
width, height, fontsize)
329-
ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float)
329+
ydata = np.full_like(xdata, (height - ydescent) / 2)
330330
legline = Line2D(xdata, ydata)
331331

332332
self.update_prop(legline, orig_handle, legend)
@@ -468,7 +468,7 @@ def create_artists(self, legend, orig_handle,
468468
xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent,
469469
width, height, fontsize)
470470

471-
ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float)
471+
ydata = np.full_like(xdata, (height - ydescent) / 2)
472472
legline = Line2D(xdata, ydata)
473473

474474
xdata_marker = np.asarray(xdata_marker)

lib/matplotlib/pyplot.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -602,26 +602,18 @@ def get_figlabels():
602602

603603

604604
def get_current_fig_manager():
605-
"""
606-
Return the figure manager of the active figure.
607-
608-
If there is currently no active figure, a new one is created.
609-
"""
610-
figManager = _pylab_helpers.Gcf.get_active()
611-
if figManager is None:
612-
gcf() # creates an active figure as a side effect
613-
figManager = _pylab_helpers.Gcf.get_active()
614-
return figManager
605+
"""Return ``gcf().canvas.manager``, the current figure's manager."""
606+
return gcf().canvas.manager
615607

616608

617609
@docstring.copy(FigureCanvasBase.mpl_connect)
618610
def connect(s, func):
619-
return get_current_fig_manager().canvas.mpl_connect(s, func)
611+
return gcf().canvas.mpl_connect(s, func)
620612

621613

622614
@docstring.copy(FigureCanvasBase.mpl_disconnect)
623615
def disconnect(cid):
624-
return get_current_fig_manager().canvas.mpl_disconnect(cid)
616+
return gcf().canvas.mpl_disconnect(cid)
625617

626618

627619
def close(fig=None):
@@ -683,7 +675,7 @@ def draw():
683675
This is equivalent to calling ``fig.canvas.draw_idle()``, where ``fig`` is
684676
the current figure.
685677
"""
686-
get_current_fig_manager().canvas.draw_idle()
678+
gcf().canvas.draw_idle()
687679

688680

689681
@docstring.copy(Figure.savefig)
@@ -1262,25 +1254,19 @@ def subplot_tool(targetfig=None):
12621254
12631255
A :class:`matplotlib.widgets.SubplotTool` instance is returned.
12641256
"""
1265-
tbar = rcParams['toolbar'] # turn off navigation toolbar for the toolfig
1266-
rcParams['toolbar'] = 'None'
12671257
if targetfig is None:
1268-
manager = get_current_fig_manager()
1269-
targetfig = manager.canvas.figure
1270-
else:
1271-
# find the manager for this figure
1272-
for manager in _pylab_helpers.Gcf._activeQue:
1273-
if manager.canvas.figure == targetfig:
1274-
break
1275-
else:
1276-
raise RuntimeError('Could not find manager for targetfig')
1258+
targetfig = gcf()
12771259

1260+
tbar = rcParams['toolbar'] # Turn off navigation toolbar for the toolfig.
1261+
rcParams['toolbar'] = 'None'
12781262
toolfig = figure(figsize=(6, 3))
12791263
toolfig.subplots_adjust(top=0.9)
1280-
ret = SubplotTool(targetfig, toolfig)
12811264
rcParams['toolbar'] = tbar
1282-
_pylab_helpers.Gcf.set_active(manager) # restore the current figure
1283-
return ret
1265+
1266+
if hasattr(targetfig.canvas, "manager"): # Restore the current figure.
1267+
_pylab_helpers.Gcf.set_active(targetfig.canvas.manager)
1268+
1269+
return SubplotTool(targetfig, toolfig)
12841270

12851271

12861272
def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):

0 commit comments

Comments
 (0)