Skip to content

Removing hard-coded values used in mplot3d #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,40 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
self.d_interval = d_intervalx
self.v_interval = v_intervalx

# This is a temporary member variable.
# Do not depend on this existing in future releases!
self._axinfo = self._AXINFO[adir].copy()
self._axinfo.update({'label' : {'space_factor': 1.3,
'va': 'center',
'ha': 'center'},
'tick' : {'inward_factor': 0.2,
'outward_factor': 0.1},
'ticklabel': {'space_factor': 0.6},
'axisline': {'linewidth': 0.75,
'color': (0, 0, 0, 1)},
'grid' : {'color': (0.9, 0.9, 0.9, 1),
'linewidth': 1.0},
})


maxis.XAxis.__init__(self, axes, *args, **kwargs)

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


def init3d(self):
self.line = mlines.Line2D(xdata=(0, 0), ydata=(0, 0),
linewidth=0.75,
color=(0, 0, 0, 1),
antialiased=True,
linewidth=self._axinfo['axisline']['linewidth'],
color=self._axinfo['axisline']['color'],
antialiased=True,
)

# Store dummy data in Polygon object
self.pane = mpatches.Polygon(np.array([[0,0], [0,1], [1,0], [0,0]]),
alpha=0.8,
facecolor=(1,1,1,0),
edgecolor=(1,1,1,0))
self.set_pane_color(self._AXINFO[self.adir]['color'])
self.set_pane_color(self._axinfo['color'])

self.axes._set_artist_props(self.line)
self.axes._set_artist_props(self.pane)
Expand Down Expand Up @@ -124,6 +140,7 @@ def set_pane_pos(self, xys):

def set_pane_color(self, color):
'''Set pane color to a RGBA tuple'''
self._axinfo['color'] = color
self.pane.set_edgecolor(color)
self.pane.set_facecolor(color)
self.pane.set_alpha(color[-1])
Expand Down Expand Up @@ -163,7 +180,7 @@ def draw_pane(self, renderer):

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

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

info = self._AXINFO[self.adir]
info = self._axinfo
index = info['i']

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

lxyz = 0.5*(edgep1 + edgep2)

labeldeltas = 1.3 * deltas
labeldeltas = info['label']['space_factor'] * deltas
axmask = [True, True, True]
axmask[index] = False
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
Expand All @@ -242,8 +259,8 @@ def draw(self, renderer):
if self.get_rotate_label(self.label.get_text()):
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
self.label.set_rotation(angle)
self.label.set_va('center')
self.label.set_ha('center')
self.label.set_va(info['label']['va'])
self.label.set_ha(info['label']['ha'])
self.label.draw(renderer)


Expand Down Expand Up @@ -333,7 +350,7 @@ def draw(self, renderer):
lines = zip(xyz1, xyz0, xyz2)
if self.axes._draw_grid:
self.gridlines.set_segments(lines)
self.gridlines.set_color([(0.9,0.9,0.9,1)] * len(lines))
self.gridlines.set_color([info['grid']['color']] * len(lines))
self.gridlines.draw(renderer, project=True)

# Draw ticks
Expand All @@ -351,15 +368,18 @@ def draw(self, renderer):
# Get tick line positions
pos = copy.copy(edgep1)
pos[index] = loc
pos[tickdir] = edgep1[tickdir] + 0.1 * ticksign * tickdelta
pos[tickdir] = edgep1[tickdir] + info['tick']['outward_factor'] * \
ticksign * tickdelta
x1, y1, z1 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
renderer.M)
pos[tickdir] = edgep1[tickdir] - 0.2 * ticksign * tickdelta
pos[tickdir] = edgep1[tickdir] - info['tick']['inward_factor'] * \
ticksign * tickdelta
x2, y2, z2 = proj3d.proj_transform(pos[0], pos[1], pos[2], \
renderer.M)

# Get position of label
labeldeltas = [0.6 * x for x in deltas]
labeldeltas = [info['ticklabel']['space_factor'] * x for
x in deltas]
axmask = [True, True, True]
axmask[index] = False
pos[tickdir] = edgep1[tickdir]
Expand Down