5

Is there a way to rotate a plot 90° within Holoviews?

I'm interested in knowing how to do that generally, but my immediate purpose is to generate a histogram that is rotated to put the frequency on the horizontal and key value on the vertical to layout next to a scatter.

This can be done quite nicely with the .hist() command, unfortunately the object that's generated (AdjointLayout) can't be nested in a HoloMap or GridSpace, so I'm left to my own devices.

import numpy as np
import holoviews as hv
hv.extension('bokeh')

data1=np.random.randn(1000)
data2=np.random.rand(1000)

dataDict1={1:hv.Scatter(data1)+hv.Histogram(np.histogram(data1),kdims=['y']),
           2:hv.Scatter(data2)+hv.Histogram(np.histogram(data2),kdims=['y'])}

dataDict2={1:hv.Scatter(data1).hist(), 2:hv.Scatter(data2).hist()}

hv.HoloMap(dataDict1).collate()  #yay!
hv.HoloMap(dataDict2).collate()  #TypeError: HoloMap does not accept AdjointLayout type, data elements have to be a ('ViewableElement', 'NdMapping', 'Layout').

I suspect it's one of the %%opts or .opts() plot options in square brackets, but I can't find the available options documented (the links are either broken, or point to the top of the API guide and I haven't found the right section of the API.)

Omegaman
  • 2,189
  • 2
  • 18
  • 30

2 Answers2

6
%%opts Histogram [invert_axes=True]

invert_xaxis reverses an axes, but invert_axes swaps the x and y axes.

The available options are much better documented through the hv.help() mechanism. ie. hv.help(hv.Histogram)

Omegaman
  • 2,189
  • 2
  • 18
  • 30
0

To have more control in plotting and in the code structure, you the option directly where it should be set :

#%%opts Bars [invert_axes=True]

import pandas as pd
import holoviews as hv
hv.extension('bokeh', 'matplotlib') # hv.notebook_extension('bokeh', 'matplotlib')

df = pd.DataFrame({'A': list(range(10,15)), 'B' : list(reversed(range(20,25)))})
hv.Bars(pd.melt(df.reset_index(), ['index']), ['index', 'variable'], 'value').opts(alpha= .7 ,  invert_axes= True, invert_yaxis= True,  )
InLaw
  • 2,537
  • 2
  • 21
  • 33