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

Display a color bar when rasterize is enabled #782

Merged
merged 3 commits into from
Jul 27, 2022

Conversation

maximlt
Copy link
Member

@maximlt maximlt commented Jul 21, 2022

Fixes #777

Before #206 the cmap style was handled as follows, i.e. when datashader was involved it was set to the default linear colormap:

        if cmap is not None:
            style_opts['cmap'] = cmap
        elif self.rasterize or self.datashade:
            style_opts['cmap'] = self._default_cmaps['linear']

#206 made hvplot behave more closely to xarray.plot() by using a symmetric colormap if the data is found to be divergent. #206 replaced the code that set the colormap to linear, by setting the color bar, to True by default:

        if cmap is not None:
            style_opts['cmap'] = cmap
        elif self.rasterize or self.datashade:
            plot_opts['colorbar'] = plot_opts.get('colorbar', True)

This PR:

  • moves up the logic that handles the datashaded path, as it seems it could be set up-front
  • sets the color bar to True by default when rasterize=True, whatever the value of cmap. This fixes the related issue. I'm not entirely sure this is the correct behavior for all plot kinds.
  • doesn't set the color bar when datashade=True as a color bar isn't relevant with this option.

@jbednar
Copy link
Member

jbednar commented Jul 21, 2022

Seems ok to me, given that hvplot seems to default to using a colorbar whenever it's relevant, and it's certainly relevant when datashading! Presumably specifying cnorm='eq_hist' overrides the linear setting?

@maximlt
Copy link
Member Author

maximlt commented Jul 22, 2022

Presumably specifying cnorm='eq_hist' overrides the linear setting?

Yes it does:

image

@philippjfr
Copy link
Member

Perfect, fix looks good!

@philippjfr philippjfr merged commit f2f1b6c into master Jul 27, 2022
@philippjfr philippjfr deleted the fix_colorbar_datashader branch July 27, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No colorbar displayed when cmap is set
3 participants