In the bokeh Holoviews gallery, there is an example called 'Scatter economic'.
http://holoviews.org/gallery/demos/bokeh/scatter_economic.html#bokeh-gallery-scatter-economic
In this plot, notice how one of the options for Scatter
is ( color=Cycle('Category20')
). The last line of the plot is gdp_unem_scatter.overlay('Country')
.
Scatter
to a particular color in Cycle('Category20')
? Is this just a property of Cycle()
? Is there some way that the Overlay
interacts with the Scatter and with the Cycle automatically?.opts
method with this cycle color on the Scatter
(ie, second to the last line in the above example), and then do an .overlay('Country')
, somehow Holoviews knows to assign each Scatter to a particular color based on the Country.I want to make sure that I am properly plotting what I intend to.
Thank you!
How does Holoviews know to connect each Scatter to a particular color in Cycle('Category20')? Is this just a property of Cycle()? Is there some way that the Overlay interacts with the Scatter and with the Cycle automatically?
You are correct that Cycle
and Overlay
are designed to interact in this way automatically. More explicitly, each color in the Cycle
gets assigned to a 'layer' of the overlay until the cycle runs out of colors and it loops.
For example, if I use the .opts method with this cycle color on the Scatter (ie, second to the last line in the above example), and then do an .overlay('Country'), somehow Holoviews knows to assign each Scatter to a particular color based on the Country.
This is because your call to opts
customizes the options on the elements of the data structure before you call the overlay
method on (this data structure is a HoloMap
). The options set there are propagated to the Scatter
elements in the HoloMap
which will now have the chosen Cycle
specified. This means that when these elements get put into an overlay, HoloViews can look up the Cycle
appropriately and apply it correctly to the overlay.
Hope that makes sense!
It is now possible to map categories in an NdOverlay (as is used in the example above) by using a so called dim expression and then define an expression to do the mapping:
dim_expr = hv.dim('category').categorize({'A': 'red', 'B': 'green', 'C': 'blue'})
overlay = hv.NdOverlay({chr(65+i): hv.Scatter(np.random.rand(10, 2)) for i in range(3)}, 'category')
overlay.opts(hv.opts.Scatter(color=dim_expr))
In this example we created a dim
expression which points to the 'category' dimension and then maps each category ('A', 'B' and 'C') to a color ('red', 'green', 'blue'). We then just assign that to the color option.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.