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

Skip to content

Commit 0430835

Browse files
committed
FIX: calculate dpi instead of relying on it being passed down properly for subfigures.
1 parent 64e898a commit 0430835

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dpi keyword argument of collections.set_sizes is removed
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The *dpi* argument of `.PathCollection.set_sizes`, `.PolyCollection.set_sizes`,
5+
`.RegularPolyCollection.set_sizes`, `.CircleCollection.set_sizes` no longer has
6+
an effect. The dpi is determined by *dpi_scale_trans* property of `.FigureBase`,
7+
which works with subfigures.

lib/matplotlib/collections.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,7 @@ def get_sizes(self):
947947
"""
948948
return self._sizes
949949

950+
@_api.delete_parameter("3.5", "dpi")
950951
def set_sizes(self, sizes, dpi=72.0):
951952
"""
952953
Set the sizes of each member of the collection.
@@ -956,15 +957,17 @@ def set_sizes(self, sizes, dpi=72.0):
956957
sizes : ndarray or None
957958
The size to set for each element of the collection. The
958959
value is the 'area' of the element.
959-
dpi : float, default: 72
960-
The dpi of the canvas.
961960
"""
962961
if sizes is None:
963962
self._sizes = np.array([])
964963
self._transforms = np.empty((0, 3, 3))
965964
else:
966965
self._sizes = np.asarray(sizes)
967966
self._transforms = np.zeros((len(self._sizes), 3, 3))
967+
dpi = 72.0
968+
if self.figure is not None:
969+
trans = self.figure.dpi_scale_trans
970+
dpi = trans.transform(np.array([1, 1]))[0]
968971
scale = np.sqrt(self._sizes) * dpi / 72.0 * self._factor
969972
self._transforms[:, 0, 0] = scale
970973
self._transforms[:, 1, 1] = scale
@@ -973,7 +976,7 @@ def set_sizes(self, sizes, dpi=72.0):
973976

974977
@artist.allow_rasterization
975978
def draw(self, renderer):
976-
self.set_sizes(self._sizes, self.figure.dpi)
979+
self.set_sizes(self._sizes)
977980
super().draw(renderer)
978981

979982

@@ -1335,7 +1338,7 @@ def get_rotation(self):
13351338

13361339
@artist.allow_rasterization
13371340
def draw(self, renderer):
1338-
self.set_sizes(self._sizes, self.figure.dpi)
1341+
self.set_sizes(self._sizes)
13391342
self._transforms = [
13401343
transforms.Affine2D(x).rotate(-self._rotation).get_matrix()
13411344
for x in self._transforms

lib/matplotlib/tests/test_figure.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,23 @@ def test_subfigure_spanning():
10311031
np.testing.assert_allclose(sub_figs[2].bbox.max, [w, h / 3])
10321032

10331033

1034+
@image_comparison(['test_subfigure_scatter_size.png'], style='mpl20',
1035+
remove_text=True)
1036+
def test_subfigure_scatter_size():
1037+
# markers in the left- and right-most subplots should be the same
1038+
fig = plt.figure()
1039+
gs = fig.add_gridspec(1, 2)
1040+
ax0 = fig.add_subplot(gs[1])
1041+
ax0.scatter([1, 2, 3], [1, 2, 3], s=30, marker='s')
1042+
ax0.scatter([3, 4, 5], [1, 2, 3], s=[20, 30, 40], marker='s')
1043+
1044+
sfig = fig.add_subfigure(gs[0])
1045+
axs = sfig.subplots(1, 2)
1046+
for ax in [ax0, axs[0]]:
1047+
ax.scatter([1, 2, 3], [1, 2, 3], s=30, marker='s', color='r')
1048+
ax.scatter([3, 4, 5], [1, 2, 3], s=[20, 30, 40], marker='s', color='g')
1049+
1050+
10341051
def test_add_subplot_kwargs():
10351052
# fig.add_subplot() always creates new axes, even if axes kwargs differ.
10361053
fig = plt.figure()

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,9 @@ def set_3d_properties(self, zs, zdir):
568568
self._vzs = None
569569
self.stale = True
570570

571+
@_api.delete_parameter("3.5", "dpi")
571572
def set_sizes(self, sizes, dpi=72.0):
572-
super().set_sizes(sizes, dpi)
573+
super().set_sizes(sizes)
573574
if not self._in_draw:
574575
self._sizes3d = sizes
575576

@@ -607,7 +608,7 @@ def do_3d_projection(self, renderer=None):
607608

608609
# we have to special case the sizes because of code in collections.py
609610
# as the draw method does
610-
# self.set_sizes(self._sizes, self.figure.dpi)
611+
# self.set_sizes(self._sizes)
611612
# so we can not rely on doing the sorting on the way out via get_*
612613

613614
if len(self._sizes3d) > 1:

0 commit comments

Comments
 (0)