Jan
July 13, 2023, 12:48am
1
In case people don’t like the “signature” style of holoviews and hvplot (italic labels and fat, left aligned title…). This here should get most plot text elements back to “normal”. Now you can publish your plots in Nature or wherever you want .
from bokeh.themes.theme import Theme
theme = Theme(json={'attrs' : {'Title': {'align':'center','text_font_size':'15px'}, # title centered and bigger
'Axis': {'axis_label_text_font_style': 'normal'}, # no italic labels
'Legend': {'title_text_font_style': 'normal'},
'ColorBar': {'title_text_font_style': 'normal'}}})
hv.renderer('bokeh').theme = theme
1 Like
Jan
July 13, 2023, 1:09am
2
And here is a code snippet to export plots to svg
, which I got from here:
holoviews
It doesn’t seem to work with layouts, which is also written in the stackoverflow post.
import holoviews as hv
from bokeh.io import export_svgs
def export_svg(obj, filename):
plot_state = hv.renderer('bokeh').get_plot(obj).state
plot_state.output_backend = 'svg'
export_svgs(plot_state, filename=filename)
overlay = hv.Overlay(...)
export_svg(overlay, 'overlay.svg')
I believe I had the same experience with returning fonts to “normal” so I created the caliber
or light_minimal
themes long ago
https://holoviews.org/user_guide/Plotting_with_Bokeh.html#theming
hv.renderer('bokeh').theme = 'light_minimal'
xs = np.linspace(0, np.pi*4, 100)
hv.Curve((xs, np.sin(xs)), label='foo')
1 Like
Jan
July 13, 2023, 1:26am
4
Oh, interesting. Here is a comparison:
Mine:
‘light-minimal’:
Jan
July 13, 2023, 1:33am
5
Maybe this here is a little better:
from bokeh.themes.theme import Theme
theme = Theme(json={'attrs' : {'Title': {'align':'center','text_font_size':'18px', 'text_font_style':'normal'}, # title centered and bigger
'Axis': {'axis_label_text_font_style': 'normal', 'axis_label_text_font_size':'14px'}, # no italic labels
'Legend': {'title_text_font_style': 'normal', 'label_text_font_size':'14px', 'title_text_font_size':'14px'},
'ColorBar': {'title_text_font_style': 'normal'}}})
hv.renderer('bokeh').theme = theme
Jan
July 13, 2023, 1:40am
7
Like this?
from bokeh.themes.theme import Theme
theme = Theme(json={'attrs' : {'Title': {'align':'center',
'text_font':'caliber',
'text_font_style':'normal',
'text_font_size':'18px'
},
'Axis': {'axis_label_text_font':'caliber',
'axis_label_text_font_style': 'normal',
'axis_label_text_font_size':'14px'
},
'Legend': {'title_text_font_style': 'normal',
'title_text_font':'caliber',
'title_text_font_size':'14px',
'label_text_font':'caliber',
'label_text_font_size':'14px'
},
'ColorBar':{'text_font':'caliber',
'title_text_font_style': 'normal',
'title_text_font_size':'14px'
}
}})
hv.renderer('bokeh').theme = theme
Jan
July 13, 2023, 1:50am
8
I think most journals would prefer sans-serif fonts for figures (Nature does). Figures are usually already so tiny. So a simple font works better.
Also, somehow the code that saves it to svg
ignores the text styling.
1 Like
This changes my x and y label texts to not be italicized but doesnt change anything on the title. Anyone knows why is it happening?
import holoviews as hv
import panel as pn
import bokeh.io
from bokeh.themes.theme import Theme
bokeh.io.output_notebook()
pn.extension()
theme = Theme(
json={
"attrs": {
"Title": {
"align": "center",
"text_font_size": "25px",
"text_font_style": "normal",
}, # title centered and bigger
"Axis": {
"axis_label_text_font_style": "normal",
"axis_label_text_font_size": "20px",
}, # no italic labels
"Legend": {
"title_text_font_style": "normal",
"label_text_font_size": "20px",
"title_text_font_size": "20px",
},
"ColorBar": {"title_text_font_style": "normal"},
}
}
)
hv.renderer("bokeh").theme = theme
xs = np.linspace(0, np.pi * 4, 100)
curve = hv.Curve((xs, np.sin(xs)), label="foo")
hv_pane = pn.pane.HoloViews(curve)
hv_pane