AttributeError: type object 'opts' has no attribute 'Curve'

Hi Everyone

I am a bokeh user, and I’ve been testing holoview, especially for the datashader intergration, allowing to get dynamic data source, reloading depending on the zoom level.
I have been struggling a lot about setting simple display options, such as Curve color and line width
I have found the doc the following doc :
http://holoviews.org/user_guide/Applying_Customizations.html
But I keep on getting the error :
curve_opts = opts.Curve(line_width=10, line_color=‘indianred’, line_dash=‘dotted’, line_alpha=0.5)
AttributeError: type object ‘opts’ has no attribute ‘Curve’

I use holoview 1.13.2

Generally speaking, I have not managed to understand anything about setting bokeh related style properties from holoview.

Thanks for the question. It’s very difficult to help without a self-contained reproducible example you are running because I cannot see all the assumptions you are making. Are you simply running the notebook as is, did you copy part of the notebook etc.?

Hi Philip
I’m using a bokeh server
Never the less, it fails before the bokeh server comes in, or even before the data comes in

import holoviews as hv
import holoviews.operation.datashader as hd
import holoviews.plotting.bokeh
from holoviews import opts
import pandas as pd
from bokeh.server.server import Server

print('holoview version: ', hv.__version__)

curve_opts = opts.Curve(line_width=10, line_color='indianred', line_dash='dotted', line_alpha=0.5)

I get as an output

curve_opts = opts.Curve(line_width=10, line_color='indianred', line_dash='dotted', line_alpha=0.5)
AttributeError: type object 'opts' has no attribute 'Curve'

The code above is self contained and reproductibe

I have edited my post reply to show a self contained reproducible code

Thanks, so it seems like the backend is not being set, which means that HoloViews doesn’t have any idea what elements are available for plotting. I would actually expect import holoviews.plotting.bokeh to do this so this is something to investigate. For now you have the option of explicitly setting the backend:

hv.Store.set_current_backend('bokeh')

or loading it via the extension:

hv.extension('bokeh')

Alright !
No crash anymore, by setting the backend or the extension
But I still cannot get to change the line color or width

curve_spectrum = hv.Curve(data_s, 'x', 'y')

overlay_s = curve_spectrum
overlay_s.opts(
    opts.Curve(line_width=10, line_color='red', tools=['hover']),
)

Anything else I should enable ? Or setup ?

curve_spectrum.opts = opts.Curve(line_width=10, line_color='red', tools=['hover'])

Doesn’t work either
Could you provide a link on a doc explaining the logic of opts ?
Can .opts bet set to a new one with = ?
Does .opts() return a copy of the object who’s opts were changed ?
Why are opts always changed via the overlay ?
I found opts and styling attribute logic very obscure.

Thanks a lot for your help so far.
Do you have more doc on when it is required to set the backend or the extension ?

This works absolutely fine for me:

curve_spectrum = hv.Curve(data_s, 'x', 'y')
curve_spectrum.opts(
    opts.Curve(line_width=10, line_color='red', tools=['hover'])
)

The getting started guide and user guide are the main explanations here. If you think they are not very intuitive, feedback would be very much appreciated.

Can .opts bet set to a new one with = ?

No, .opts is a method, assigning it won’t do anything.

Does .opts() return a copy of the object who’s opts were changed ?

No, .opts is one of the few methods in HoloViews which modify an object in place.

Why are opts always changed via the overlay ?

They aren’t, the hv.opts.<Element>() object just let’s you specify objects on a composite object, if you have a single element it’s fine to simple set the options directly on it, e.g. this is a perfectly valid way to set options on a Curve:

hv.Curve(...).opts(line_width=2)

I found opts and styling attribute logic very obscure.

Everyone has different experiences, and HoloViews is certainly a very different way to think about visualization. The options system is one of the ways HoloViews supports having different plotting backends with very different sets of valid options.

Do you have more doc on when it is required to set the backend or the extension ?

If you want to visualize anything it is always required to select a plotting extension and all our docs start with a call to the extension. I do think this aspect is very much under-documented however and should be probably be addressed in the very first getting started guide.

Thanks for the very fast and complete answer
I have to admit that I found the threshold to learn holoview a bit big, especially when not using a notebook
I’ll give feedback when I get to try (and hopefully solve) my styling issues

Cheers