10

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!

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
Amen_90
  • 310
  • 2
  • 9
  • oh, just one more thing. If you ask a new question on stackoverflow try to add a code example like the one I gave in my answer. It really helps figuring out your precise problem. – Sander van den Oord Jan 09 '20 at 17:16

3 Answers3

10

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

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96
  • Hi Sander, I was just wondering you know if i can do same if I have used ".plot" to create my holoview charts? – Amen_90 Jan 15 '20 at 13:59
  • 1
    Did you try? :) You can indeed do: (df1.plot.scatter(x='x', y='y') + df2.plot.scatter(x='x', y='y')).opts(opts.Scatter(axiswise=True)) – Sander van den Oord Jan 15 '20 at 14:07
  • 2
    But to be honest I myself rather you use: import hvplot.pandas; and then: (df1.hvplot.scatter(x='x', y='y') + df2.hvplot.scatter(x='x', y='y')).opts(opts.Scatter(axiswise=True)) So you're using .hvplot() then instead of .plot() which is basically what you're doing when you set the plotting backend to holoviews. You should really check out: https://hvplot.holoviz.org/ Hvplot is what is really being used. – Sander van den Oord Jan 15 '20 at 14:09
  • Thanks so much Sander, this worked! Yes, I certainly will in future! I've got quite far with this project using .plot! This is really great though, means I do not have to start over several hours of cleaning and pivoting I've already done! =) – Amen_90 Jan 15 '20 at 14:14
4

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.

James A. Bednar
  • 3,195
  • 1
  • 9
  • 13
  • Thank you for the reply! Just a quick additional question. Does the above work when working with matplotlib with 'holoviews' as the backend? Can't seem to get the code to work in this instance. – Amen_90 Jan 14 '20 at 10:59
  • Yes, that behavior should be the same across all plotting libraries supported by HoloViews. If you find a problem, please make a small example and file an issue on https://github.com/holoviz/holoviews. – James A. Bednar Jan 15 '20 at 18:50
  • Hi James. Thanks for the explanation. But this behaviour of holoview does not make sense to me. Why holoviews decides axis - sharing on the axis name? The end user might be plotting completely independent figures. but with same axis names. Axis - linking or sharing should be only possible with an extra argument. Unless I wrap them in pn.row or pn.Column, I did not see any axis -linking by the way. – Enis Arik Jul 20 '20 at 21:49
  • HoloViews is a high-level library built on the idea that when you declare semantically relevant information (such as the dimension labels and units for your data), this information will be respected throughout the visualization process. – James A. Bednar Jul 21 '20 at 22:16
  • 1
    Thus if you create two plots that share the same axes, then put them next to each other in one layout, HoloViews links the two axes under the assumption that you must be wanting to compare the data in plot A with the data in plot B; otherwise why would they be in the same layout? You can always turn off the auto-linking, but the library is designed to respect the information you declared. – James A. Bednar Jul 21 '20 at 22:16
4

I have tried setting xlim and ylim, setting axiswise=True and many other things with no success.

The thing that ultimately solved the issue was to set your_layout.opts(shared_axes=False).

Read more here.

Jurgen Strydom
  • 3,540
  • 1
  • 23
  • 30