Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Holoviews charts sharing axis when combined and outputted

I'm using Holoviews to construct a dashboard of charts. Some of these charts have percentages in the y axis where as others have sums/counts etc. When I try to output all the charts I have created to a html file, all the charts change their y axis to match the axis of the first chart of my chart list.

For example:

  • Chart 1 is a sum, values go from 0 to 1000
  • Chart 2 is a %
  • Chart 3 is a %

when I combine these charts in holoviews using:

  • Charts = Chart 1 + Chart 2 + Chart 3

The y axis of charts 2 and 3 become the same as chart 1.

Does anyone know why this is happening and how I can fix it so all the charts keep their individual axis pertinent to what they are trying to represent.

Thank you!

like image 584
Amen_90 Avatar asked Jan 09 '20 09:01

Amen_90


2 Answers

This happens when the y-axes have the same name.
You need to use option axiswise=True if you want every plot to get its own independent x-axis and y-axis.

There's a short reference to axiswise in the holoviews FAQ:
https://www.holoviews.org/FAQ.html

Here's a code example that I've checked and works:

# import libraries etc.
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

# create some sample data
df1 = pd.DataFrame({
    'x': np.random.rand(10), 
    'y': np.random.rand(10),
})

df2 = pd.DataFrame({
    'x': np.random.rand(10) * 10, 
    'y': np.random.rand(10) * 10,
})

# set axiswise=True so that every plot gets its own independent x- and y-axis    
plot1 = hv.Scatter(df1).opts(axiswise=True)
plot2 = hv.Scatter(df2).opts(axiswise=True)

plot1 + plot2

Or alternatively you can do:

plot1 = hv.Scatter(df1)
plot2 = hv.Scatter(df2)

(plot1 + plot2).opts(opts.Scatter(axiswise=True))


If this doesn't work when you try my code example, you may have to upgrade to the latest version of holoviews. This can be done as follows:
Install the latest git versions of holoviews, hvplot, panel, datashader and param

like image 116
Sander van den Oord Avatar answered Sep 29 '22 14:09

Sander van den Oord


Sander's response is correct and will solve your specific problem, but in this case it may not be addressing the root cause. HoloViews only links axes that are the same, and it sounds like you're plotting different quantities on the y axis in each plot. In that case, the real fix is to put in a real name for the y axis of each plot, something that distinguishes it from other things that you might want to plot on the y axis in some other plot you're showing. Then not only will HoloViews no longer link the axes inappropriately, the viewer of your plot will be able to tell that each plot is showing different things.

like image 30
James A. Bednar Avatar answered Sep 29 '22 13:09

James A. Bednar