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

Skip to content

Commit 7c1cd9b

Browse files
committed
Merge pull request #137 from WeatherGod/mplot3d/axes3d_simplify
Removing hard-coded values used in mplot3d
2 parents 814fbae + 75ae962 commit 7c1cd9b

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,40 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
7272
self.d_interval = d_intervalx
7373
self.v_interval = v_intervalx
7474

75+
# This is a temporary member variable.
76+
# Do not depend on this existing in future releases!
77+
self._axinfo = self._AXINFO[adir].copy()
78+
self._axinfo.update({'label' : {'space_factor': 1.3,
79+
'va': 'center',
80+
'ha': 'center'},
81+
'tick' : {'inward_factor': 0.2,
82+
'outward_factor': 0.1},
83+
'ticklabel': {'space_factor': 0.6},
84+
'axisline': {'linewidth': 0.75,
85+
'color': (0, 0, 0, 1)},
86+
'grid' : {'color': (0.9, 0.9, 0.9, 1),
87+
'linewidth': 1.0},
88+
})
89+
90+
7591
maxis.XAxis.__init__(self, axes, *args, **kwargs)
7692

7793
self.set_rotate_label(kwargs.get('rotate_label', None))
7894

7995

8096
def init3d(self):
8197
self.line = mlines.Line2D(xdata=(0, 0), ydata=(0, 0),
82-
linewidth=0.75,
83-
color=(0, 0, 0, 1),
84-
antialiased=True,
98+
linewidth=self._axinfo['axisline']['linewidth'],
99+
color=self._axinfo['axisline']['color'],
100+
antialiased=True,
85101
)
86102

87103
# Store dummy data in Polygon object
88104
self.pane = mpatches.Polygon(np.array([[0,0], [0,1], [1,0], [0,0]]),
89105
alpha=0.8,
90106
facecolor=(1,1,1,0),
91107
edgecolor=(1,1,1,0))
92-
self.set_pane_color(self._AXINFO[self.adir]['color'])
108+
self.set_pane_color(self._axinfo['color'])
93109

94110
self.axes._set_artist_props(self.line)
95111
self.axes._set_artist_props(self.pane)
@@ -124,6 +140,7 @@ def set_pane_pos(self, xys):
124140

125141
def set_pane_color(self, color):
126142
'''Set pane color to a RGBA tuple'''
143+
self._axinfo['color'] = color
127144
self.pane.set_edgecolor(color)
128145
self.pane.set_facecolor(color)
129146
self.pane.set_alpha(color[-1])
@@ -163,7 +180,7 @@ def draw_pane(self, renderer):
163180

164181
mins, maxs, centers, deltas, tc, highs = self._get_coord_info(renderer)
165182

166-
info = self._AXINFO[self.adir]
183+
info = self._axinfo
167184
index = info['i']
168185
if not highs[index]:
169186
plane = self._PLANES[2 * index]
@@ -183,7 +200,7 @@ def draw(self, renderer):
183200
majorTicks = self.get_major_ticks()
184201
majorLocs = self.major.locator()
185202

186-
info = self._AXINFO[self.adir]
203+
info = self._axinfo
187204
index = info['i']
188205

189206
# filter locations here so that no extra grid lines are drawn
@@ -232,7 +249,7 @@ def draw(self, renderer):
232249

233250
lxyz = 0.5*(edgep1 + edgep2)
234251

235-
labeldeltas = 1.3 * deltas
252+
labeldeltas = info['label']['space_factor'] * deltas
236253
axmask = [True, True, True]
237254
axmask[index] = False
238255
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
@@ -242,8 +259,8 @@ def draw(self, renderer):
242259
if self.get_rotate_label(self.label.get_text()):
243260
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
244261
self.label.set_rotation(angle)
245-
self.label.set_va('center')
246-
self.label.set_ha('center')
262+
self.label.set_va(info['label']['va'])
263+
self.label.set_ha(info['label']['ha'])
247264
self.label.draw(renderer)
248265

249266

@@ -333,7 +350,7 @@ def draw(self, renderer):
333350
lines = zip(xyz1, xyz0, xyz2)
334351
if self.axes._draw_grid:
335352
self.gridlines.set_segments(lines)
336-
self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines))
353+
self.gridlines.set_color([info['grid']['color']] * len(lines))
337354
self.gridlines.draw(renderer, project=True)
338355

339356
# Draw ticks
@@ -351,15 +368,18 @@ def draw(self, renderer):
351368
# Get tick line positions
352369
pos = copy.copy(edgep1)
353370
pos[index] = loc
354-
pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta
371+
pos[tickdir] = edgep1[tickdir] + info['tick']['outward_factor'] * \
372+
ticksign * tickdelta
355373
x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
356374
renderer.M)
357-
pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta
375+
pos[tickdir] = edgep1[tickdir] - info['tick']['inward_factor'] * \
376+
ticksign * tickdelta
358377
x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
359378
renderer.M)
360379

361380
# Get position of label
362-
labeldeltas = [0.6 * x for x in deltas]
381+
labeldeltas = [info['ticklabel']['space_factor'] * x for
382+
x in deltas]
363383
axmask = [True, True, True]
364384
axmask[index] = False
365385
pos[tickdir] = edgep1[tickdir]

0 commit comments

Comments
 (0)