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

Skip to content

Commit dbed8a0

Browse files
authored
Merge pull request #13358 from neok-m4700/isometric
3D margins consistency for mplot3d (isometric projection)
2 parents 0faffab + 933f06d commit dbed8a0

File tree

5 files changed

+22
-1
lines changed

5 files changed

+22
-1
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ def _convert_validator_spec(key, conv):
11901190
"axes.autolimit_mode": ["data", "round_numbers"],
11911191
"axes.xmargin": _range_validators["0 <= x <= 1"], # margin added to xaxis
11921192
"axes.ymargin": _range_validators["0 <= x <= 1"], # margin added to yaxis
1193+
'axes.zmargin': _range_validators["0 <= x <= 1"], # margin added to zaxis
11931194

11941195
"polaraxes.grid": validate_bool, # display polar grid or not
11951196
"axes3d.grid": validate_bool, # display 3d grid

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,10 @@ def cla(self):
11781178
pass
11791179

11801180
self._autoscaleZon = True
1181-
self._zmargin = 0
1181+
if self._projection is proj3d.ortho_transformation:
1182+
self._zmargin = rcParams['axes.zmargin']
1183+
else:
1184+
self._zmargin = 0.
11821185

11831186
self.grid(rcParams['axes3d.grid'])
11841187

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,22 @@ def test_axes3d_ortho():
947947
ax.set_proj_type('ortho')
948948

949949

950+
@mpl3d_image_comparison(['axes3d_isometric.png'])
951+
def test_axes3d_isometric():
952+
from itertools import combinations, product
953+
fig, ax = plt.subplots(subplot_kw=dict(
954+
projection='3d',
955+
proj_type='ortho',
956+
box_aspect=(4, 4, 4)
957+
))
958+
r = (-1, 1) # stackoverflow.com/a/11156353
959+
for s, e in combinations(np.array(list(product(r, r, r))), 2):
960+
if abs(s - e).sum() == r[1] - r[0]:
961+
ax.plot3D(*zip(s, e), c='k')
962+
ax.view_init(elev=np.degrees(np.arctan(1. / np.sqrt(2))), azim=-45)
963+
ax.grid(True)
964+
965+
950966
@pytest.mark.parametrize('value', [np.inf, np.nan])
951967
@pytest.mark.parametrize(('setter', 'side'), [
952968
('set_xlim3d', 'left'),

matplotlibrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@
417417
# for more details on prop_cycle usage.
418418
#axes.xmargin: .05 # x margin. See `axes.Axes.margins`
419419
#axes.ymargin: .05 # y margin. See `axes.Axes.margins`
420+
#axes.zmargin: .05 # z margin. See `axes.Axes.margins`
420421
#axes.autolimit_mode: data # If "data", use axes.xmargin and axes.ymargin as is.
421422
# If "round_numbers", after application of margins, axis
422423
# limits are further expanded to the nearest "round" number.

0 commit comments

Comments
 (0)