8000 Add ability to scale BBox with just x or y values · matplotlib/matplotlib@432fb08 · GitHub
[go: up one dir, main page]

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 432fb08

Browse files
committed
Add ability to scale BBox with just x or y values
1 parent a9bba75 commit 432fb08

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

lib/matplotlib/transforms.py

Lines 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

Lines 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(np.column_stack([X, Y]),
649+
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

0 commit comments

Comments
 (0)
0