Skip to content
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

Matplotlib aspect fixes #1209

Merged
merged 5 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
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
28 changes: 17 additions & 11 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ def _finalize_axis(self, key, title=None, dimensions=None, ranges=None, xticks=N
if dimensions:
self._set_labels(axis, dimensions, xlabel, ylabel, zlabel)

# Set axes limits
self._set_axis_limits(axis, element, subplots, ranges)

if not subplots:
legend = axis.get_legend()
if legend:
Expand All @@ -199,8 +196,11 @@ def _finalize_axis(self, key, title=None, dimensions=None, ranges=None, xticks=N
if self.apply_ticks:
self._finalize_ticks(axis, dimensions, xticks, yticks, zticks)

# Set axes limits
self._set_axis_limits(axis, element, subplots, ranges)

# Apply aspects
if not (self.logx or self.logy):
if self.aspect is not None and self.projection != 'polar':
self._set_aspect(axis, self.aspect)

if not subplots and not self.drawn:
Expand Down Expand Up @@ -296,13 +296,19 @@ def _set_aspect(self, axes, aspect):
"""
Set the aspect on the axes based on the aspect setting.
"""
if aspect and aspect == 'square':
axes.set_aspect((1./axes.get_data_ratio()))
elif aspect not in [None, 'square']:
if isinstance(aspect, util.basestring):
axes.set_aspect(aspect)
else:
axes.set_aspect(((1./axes.get_data_ratio()))/aspect)
if isinstance(aspect, util.basestring) and aspect != 'square':
axes.set_aspect(aspect)
return

(x0, x1), (y0, y1) = axes.get_xlim(), axes.get_ylim()
xsize = np.log(x1) - np.log(x0) if self.logx else x1-x0
ysize = np.log(y1) - np.log(y0) if self.logy else y1-y0
xsize = max(abs(xsize), 1e-30)
ysize = max(abs(ysize), 1e-30)
data_ratio = 1./(ysize/xsize)
if aspect != 'square':
data_ratio = data_ratio/aspect
axes.set_aspect(data_ratio)


def _set_axis_limits(self, axis, view, subplots, ranges):
Expand Down
2 changes: 0 additions & 2 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,6 @@ def _create_subplots(self, layout, positions, layout_dimensions, ranges, axes={}
own_params = self.get_param_values(onlychanged=True)
sublabel_opts = {k: v for k, v in own_params
if 'sublabel_' in k}
if not isinstance(view, GridSpace):
override_opts = dict(aspect='square')
elif pos == 'right':
right_opts = dict(invert_axes=True,
xaxis=None)
Expand Down