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

Styling individual elements in a GridMatrix is ignored by datashade operation #2698

Closed
suyang-nju opened this issue May 19, 2018 · 10 comments
Closed

Comments

@suyang-nju
Copy link

The following code tries to set the background and frame colors of one plot in a GridMatrix:

def modify_frame(plot, element):
    print('modify_frame')
    plot.state.outline_line_color = 'blue'

some_dataset = hv.Dataset(np.random.normal(size=(10000, 3)), [chr(65+i)+'_dimension' for i in range(3)])
gd = gridmatrix(some_dataset)
gd['A_dimension', 'B_dimension'].options(finalize_hooks=[modify_frame], bgcolor='lightyellow', clone=False)
gd.map(datashade, hv.Scatter)

but there's no color changes, and no output from the print() in modify_frame. It seemed that modify_frame was not called. If the last line was gd or gd.map(decimate, hv.Scatter), the code worked as expected. Somehow datashade 'eats' the options?

@suyang-nju suyang-nju changed the title Styling individual elements in a GridMatrix is ignored by datashader operation Styling individual elements in a GridMatrix is ignored by datashade operation May 19, 2018
@jbednar
Copy link
Member

jbednar commented May 19, 2018

I think this is a specific case of the issue in #2637 . I agree it's confusing, and I'd really like to find a solution.

@philippjfr
Copy link
Member

As @jbednar points out this is a duplicate of #2637, so I'll close. For now the correct thing to do is to apply the plot options after datashading.

@suyang-nju
Copy link
Author

suyang-nju commented May 22, 2018

@philippjfr Applying the plot options after datashading still has no effect:

gd = hv.operation.gridmatrix(some_dataset).map(hd.datashade, hv.Scatter)
gd['A_dimension', 'B_dimension'].options(finalize_hooks=[modify_frame], bgcolor='lightyellow', clone=False)
gd

Interestingly, the plot options are set and can be seen if only that plot is shown:

gd['A_dimension', 'B_dimension'].options(finalize_hooks=[modify_frame], bgcolor='lightyellow', clone=False)

will show a plot with lightyellow background and blue frame. But when the plot is shown together with other plots in a GridMatrix with gd, the plot options are lost. In both cases, the plot options are applied after datashaing.

bokeh_plot

@jbednar
Copy link
Member

jbednar commented May 22, 2018

It's possible to use these tools without having to think deeply about how it all works, and we try to facilitate that where practical, but sometimes you have to appreciate all of the details, especially if you want to control them. Here, Datashader returns transparent images, which will reveal the background color of the plot the same as if you hadn't used datashader. But datashade() controls the foreground color, so you have to pass that to the datashade() operation if you want to change that. And datashade() also changes the plot from being a point plot to an RBG plot, so options that apply to points aren't relevant after datashade(). You can use more of the usual styling mechanisms if you use rasterize() instead of datashade(), where Bokeh controls the assignment of colors and Datashader is only responsible for the rasterizing/aggregating step. If you do use rasterize(), and are aware that it turns the data into an hv.Image() and apply options suitable for an Image, you'll probably be able to achieve what you want.

@suyang-nju
Copy link
Author

Thanks @jbednar. The same issue happens when I use rasterize(). I played with the code a bit more and the result is even more puzzling.

I understand I'm dealing with RGB elements after datashade(), and should apply options for RGB. RGB elements have the bgcolor and finalize_hooks options, and those options are indeed applied (see picture in my last comment) if I only show that RGB element by

gd['A_dimension', 'B_dimension'].options(..., clone=False) # works

The plot options are not set when I try to set the options of one plot and then show the whole gridmatrix in one cell:

gd['A_dimension', 'B_dimension'].options(..., clone=False) # doesn't work
gd # doesn't work

The modify_frame function I passed to finalize_hooks is not even called in this situation (because no output from the print() in the function).

More puzzling is if I put the following three lines in three separate cells, everything is fine, the plot options are applied

  1. gd['A_dimension', 'B_dimension'].options(..., clone=False)
  2. gd['A_dimension', 'B_dimension']
  3. gd
    bokeh_plot5

But if I put 1) and 2) in the same cell, and 3) in a separate cell, then the plot options are not applied at all
bokeh_plot6

@jbednar
Copy link
Member

jbednar commented May 22, 2018

Hmm. That doesn't sound like it's behaving properly, to me. @philippjfr?

@jbednar
Copy link
Member

jbednar commented May 22, 2018

Might be hard to test without a runnable reproducing example.

@suyang-nju
Copy link
Author

suyang-nju commented May 22, 2018

This is the code I used in the screenshots, run in jupyter lab or notebook environment.

def modify_frame(plot, element):
    print(element)
    plot.state.outline_line_color = 'orange'
    plot.state.outline_line_width = 8

some_dataset = hv.Dataset(np.random.normal(size=(10000, 3)), [chr(65+i)+'_dimension' for i in range(3)])
gd = hv.operation.gridmatrix(some_dataset).map(hd.datashade, hv.Scatter).map(hd.dynspread, hv.RGB)

gd['A_dimension', 'B_dimension'].options(finalize_hooks=[modify_frame], bgcolor='lightyellow', clone=False)
gd['A_dimension', 'B_dimension']
gd

@philippjfr
Copy link
Member

Thanks, that makes it much easier. That is indeed strange behavior.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants