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

Fix matplotlib colorbar labeling for dim expressions #5137

Merged
merged 2 commits into from
Nov 16, 2021
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
4 changes: 4 additions & 0 deletions holoviews/plotting/mpl/chart3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ...core import Dimension
from ...core.options import abbreviated_exception
from ...util.transform import dim as dim_expr
from ..util import map_colors
from .element import ColorbarPlot
from .chart import PointPlot
Expand Down Expand Up @@ -91,6 +92,8 @@ def _draw_colorbar(self, element=None, dim=None, redraw=True):
fig = self.handles['fig']
ax = self.handles['axis']
# Get colorbar label
if isinstance(dim, dim_expr):
dim = dim.dimension
if dim is None:
if hasattr(self, 'color_index'):
dim = element.get_dimension(self.color_index)
Expand All @@ -100,6 +103,7 @@ def _draw_colorbar(self, element=None, dim=None, redraw=True):
dim = element.get_dimension(dim)
label = dim.pprint_label
cbar = fig.colorbar(artist, shrink=0.7, ax=ax)
self.handles['cbar'] = cbar
self.handles['cax'] = cbar.ax
self._adjust_cbar(cbar, label, dim)

Expand Down
5 changes: 5 additions & 0 deletions holoviews/tests/plotting/matplotlib/test_scatter3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

class TestPointPlot(TestMPLPlot):

def test_scatter3d_colorbar_label(self):
scatter3d = Scatter3D([(0, 1, 2), (1, 2, 3), (2, 3, 4)]).options(color='z', colorbar=True)
plot = mpl_renderer.get_plot(scatter3d)
assert plot.handles['cax'].get_ylabel() == 'z'

def test_scatter3d_padding_square(self):
scatter3d = Scatter3D([(0, 1, 2), (1, 2, 3), (2, 3, 4)]).options(padding=0.1)
plot = mpl_renderer.get_plot(scatter3d)
Expand Down