holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

title for adjoint layouts is applied to each element #2816

Open ea42gh opened 6 years ago

ea42gh commented 6 years ago
x_vals = .3*np.random.normal(size=500)+5
y_vals = np.random.normal(size=500)
h=\
hv.Scatter((x_vals,y_vals)).redim.range(x=(0,10))<<\
hv.Distribution( y_vals, 'y').options(width=150)<<\
hv.Distribution( x_vals, 'x').options(height=150)
h.relabel('Title')

results in the title to be applied to each hv Element in the plot

Adding a Div to insert a title runs into width/height issues: The Div below does not start at the same left hand side as the plot, and there appears to be an additional element off to the top right:

x_vals = .3*np.random.normal(size=500)+5
y_vals = np.random.normal(size=500)

def plot():
    if hv.Store.current_backend == 'matplotlib':
        o_rgt = {'aspect':0.5}
        o_top = {'aspect':2.5}
        h1=\
        (hv.Scatter((x_vals,y_vals)).redim.range(x=(0,10))<<\
        hv.Distribution( y_vals, 'y').options(**o_rgt)<<\
        hv.Distribution( x_vals, 'x').options(**o_top))
    else:
        o_rgt = {'width' :150}
        o_top = {'height':150}
        h1=\
        hv.Div('<div style=\"color:black;background-color:#88FF88;text-align:center;font-size:20px">Overall Title</div>').options(height=10,width=450)+\
        (hv.Scatter((x_vals,y_vals)).redim.range(x=(0,10))<<\
        hv.Distribution( y_vals, 'y').options(**o_rgt)<<\
        hv.Distribution( x_vals, 'x').options(**o_top))
        h1 = h1.cols(1)
    return h1.relabel('PLOT')

print('BOKEH')
renderer = hv.Store.renderers['bokeh'].instance(fig='png', holomap='auto')
renderer.save(plot(),'/tmp/aaa')
hv.Store.current_backend='matplotlib'
print('MATPLOTLIB')
renderer = hv.Store.renderers['matplotlib'].instance(fig='svg', holomap='gif')
renderer.save(plot(),'/tmp/bbb')
print('BOKEH in the notebook')
hv.Store.current_backend='bokeh'
plot()

Relabeling the topmost plot does work in bokeh; note the layout problems when viewed with say eog in Linux

aaa

ea42gh commented 6 years ago

Not sure about that fix: consistency would require that the AdjointLayout plot as a whole gets a title, rather than one of the elements composing it: I can always add a title to each of the elements

x_vals = .3*np.random.normal(size=500)+5
y_vals = np.random.normal(size=500)
h=\
(hv.Scatter((x_vals,y_vals)).redim.range(x=(0,10))).relabel('scatterplot')<<\
hv.Distribution( y_vals, 'y').options(width=150)<<\
hv.Distribution( x_vals, 'x').options(height=150)
h

calling h.relabel('plot title') now changes the scatterplot title....

ea42gh commented 6 years ago

Setting yaxis and xaxis to None for the right and top plots results in too big a gap between the plots in matplotlib. How can that get adjusted?

bbb

ea42gh commented 6 years ago

Also note that the top distribution is not correct in matplotlib: tha axes are independent?!

philippjfr commented 6 years ago

Also note that the top distribution is not correct in matplotlib: the axes are independent?!

Looks like it. I'll try to add fixes for both.

ea42gh commented 6 years ago

I think an example like this would make a great HowTo:

If you have suggestions for improvements of the routine, I'd love to see them!

TomBugnon commented 5 years ago

Any activity on this? I can't figure out how set a title on an AdjointLayout. Calling adjointlayout.relabel or adjointlayout.opts(...) throws TypeError: __init__() got an unexpected keyword argument 'cdims' Help would be much appreciated

ea42gh commented 5 years ago

A workaround would be to add an hv.Div() with a title to the Figure as a whole

wmayner commented 4 years ago

I'm having the same problem.