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 b0e68b2

Browse filesBrowse files
committed
Add ability to scale BBox with just x or y values
1 parent 7f92f6a commit b0e68b2
Copy full SHA for b0e68b2

File tree

Expand file treeCollapse file tree

3 files changed

+62
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+62
-10
lines changed

‎lib/matplotlib/transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/transforms.py
+43-3Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,51 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
902902
self._points[:, 1] = points[:, 1]
903903
self._minpos[1] = minpos[1]
904904

905+
def update_from_data_x(self, x, ignore=None):
906+
"""
907+
Update the x-bounds of the `Bbox` based on the passed in data. After
908+
updating, the bounds will have positive *width*, and *x0* will be the
909+
minimal value.
910+
911+
Parameters
912+
----------
913+
x : ndarray
914+
Array of x-values.
915+
916+
ignore : bool, optional
917+
- When ``True``, ignore the existing bounds of the `Bbox`.
918+
- When ``False``, include the existing bounds of the `Bbox`.
919+
- When ``None``, use the last value passed to :meth:`ignore`.
920+
"""
921+
x = np.ravel(x)
922+
self.update_from_data_xy(np.column_stack([x, np.ones(x.size)]),
923+
ignore=ignore, updatey=False)
924+
925+
def update_from_data_y(self, y, ignore=None):
926+
"""
927+
Update the y-bounds of the `Bbox` based on the passed in data. After
928+
updating, the bounds will have positive *height*, and *y0* will be the
929+
minimal value.
930+
931+
Parameters
932+
----------
933+
y : ndarray
934+
Array of y-values.
935+
936+
ignore : bool, optional
937+
- When ``True``, ignore the existing bounds of the `Bbox`.
938+
- When ``False``, include the existing bounds of the `Bbox`.
939+
- When ``None``, use the last value passed to :meth:`ignore`.
940+
"""
941+
y = np.array(y).ravel()
942+
self.update_from_data_xy(np.column_stack([np.ones(y.size), y]),
943+
ignore=ignore, updatex=False)
944+
905945
def update_from_data_xy(self, xy, ignore=None, updatex=True, updatey=True):
906946
"""
907-
Update the bounds of the `Bbox` based on the passed in
908-
data. After updating, the bounds will have positive *width*
909-
and *height*; *x0* and *y0* will be the minimal values.
947+
Update the bounds of the `Bbox` based on the passed in data. After
948+
updating, the bounds will have positive *width* and *height*;
949+
*x0* and *y0* will be the minimal values.
910950
911951
Parameters
912952
----------

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def __init__(
107107
self.xy_viewLim = Bbox.unit()
108108
self.zz_viewLim = Bbox.unit()
109109
self.xy_dataLim = Bbox.unit()
110+
# z-limits are encoded in the x-component of the Bbox, y is un-used
110111
self.zz_dataLim = Bbox.unit()
111112

112113
# inhibit autoscale_view until the axes are defined
@@ -643,14 +644,14 @@ def autoscale(self, enable=True, axis='both', tight=None):
643644
def auto_scale_xyz(self, X, Y, Z=None, had_data=None):
644645
# This updates the bounding boxes as to keep a record as to what the
645646
# minimum sized rectangular volume holds the data.
646-
X = np.reshape(X, -1)
647-
Y = np.reshape(Y, -1)
648-
self.xy_dataLim.update_from_data_xy(
649-
np.column_stack([X, Y]), not had_data)
647+
if np.shape(X) == np.shape(Y):
648+
self.xy_dataLim.update_from_data_xy(
649+
np.column_stack([np.ravel(X), np.ravel(Y)]), not had_data)
650+
else:
651+
self.xy_dataLim.update_from_data_x(X, not had_data)
652+
self.xy_dataLim.update_from_data_y(Y, not had_data)
650653
if Z is not None:
651-
Z = np.reshape(Z, -1)
652-
self.zz_dataLim.update_from_data_xy(
653-
np.column_stack([Z, Z]), not had_data)
654+
self.zz_dataLim.update_from_data_x(Z, not had_data)
654655
# Let autoscale_view figure out how to use this data.
655656
self.autoscale_view()
656657

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ def test_tricontour():
198198
ax.tricontourf(x, y, z)
199199

200200

201+
def test_contour3d_1d_input():
202+
# Check that 1D sequences of different length for {x, y} doesn't error
203+
fig = plt.figure()
204+
ax = fig.add_subplot(projection='3d')
205+
nx, ny = 30, 20
206+
x = np.linspace(-10, 10, nx)
207+
y = np.linspace(-10, 10, ny)
208+
z = np.random.randint(0, 2, [ny, nx])
209+
ax.contour(x, y, z, [0.5])
210+
211+
201212
@mpl3d_image_comparison(['lines3d.png'])
202213
def test_lines3d():
203214
fig = plt.figure()

0 commit comments

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