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

Appearance settings

Commit e0139d0

Browse filesBrowse files
authored
Merge pull request #25920 from oscargus/offsetcopy
Rewrite offset_copy for better error message
2 parents 85eadb3 + 5ec00ce commit e0139d0
Copy full SHA for e0139d0

File tree

Expand file treeCollapse file tree

2 files changed

+13
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-4
lines changed

‎lib/matplotlib/tests/test_transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_transforms.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,3 +744,14 @@ def test_scale_swapping(fig_test, fig_ref):
744744
ax.plot(x, np.exp(-(x**2) / 2) / np.sqrt(2 * np.pi))
745745
fig.canvas.draw()
746746
ax.set_yscale('linear')
747+
748+
749+
def test_offset_copy_errors():
750+
with pytest.raises(ValueError,
751+
match="'fontsize' is not a valid value for units;"
752+
" supported values are 'dots', 'points', 'inches'"):
753+
mtransforms.offset_copy(None, units='fontsize')
754+
755+
with pytest.raises(ValueError,
756+
match='For units of inches or points a fig kwarg is needed'):
757+
mtransforms.offset_copy(None, units='inches')

‎lib/matplotlib/transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/transforms.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,15 +2952,13 @@ def offset_copy(trans, fig=None, x=0.0, y=0.0, units='inches'):
29522952
`Transform` subclass
29532953
Transform with applied offset.
29542954
"""
2955+
_api.check_in_list(['dots', 'points', 'inches'], units=units)
29552956
if units == 'dots':
29562957
return trans + Affine2D().translate(x, y)
29572958
if fig is None:
29582959
raise ValueError('For units of inches or points a fig kwarg is needed')
29592960
if units == 'points':
29602961
x /= 72.0
29612962
y /= 72.0
2962-
elif units == 'inches':
2963-
pass
2964-
else:
2965-
_api.check_in_list(['dots', 'points', 'inches'], units=units)
2963+
# Default units are 'inches'
29662964
return trans + ScaledTranslation(x, y, fig.dpi_scale_trans)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.