Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Create a template for multiple figures using Plotly in Python

$
0
0

I am trying to create a template for a heatmap and a line chart using Plotly in Python. I want to use the combination of this template as well as the plotly_white.However, combining them remove the colors of the colorscale for my heatmap.

Combining my template with the plotly_white removes the color of the heatmap

The colorscale I want for my heatmap are those. I still get them by only using mytemplate

I define my template in the following function

THEME = {'background_color': '#ffffff','font_family': 'Roboto','accent_font_family': 'Roboto Slab','dark_color': '#2A2B2E','pale_color': '#DFD9E2','line_chart_color': 'black','label_font_size': 14,'label_background_color': '#ffffff','colorscale': 'Bluyl'}def create_custom_theme():    pio.templates['mytemplate'] = go.layout.Template(        layout=go.Layout(            font=dict(                family=THEME['font_family']+' , '+ THEME['accent_font_family'],                color=THEME['dark_color']            ),            paper_bgcolor=THEME['background_color'],            plot_bgcolor=THEME['background_color'],            hoverlabel=dict(                bgcolor=THEME['label_background_color'],                font=dict(                    size=THEME['label_font_size']                )            ),            hovermode="closest",            newshape=dict(                line_color=THEME['line_chart_color']            ),            colorscale=dict(diverging=THEME['colorscale']),             xaxis=dict(                tickangle=-45            )        )    )

And set it as default like this

def set_default_theme():    pio.templates.default='mytemplate+plotly_white'

Also, I am wondering if it is possible to use the two font families defined in the template, in the hovertemplate. For now, I use span to avoid using the template

def get_heatmap_hover_template():    return ('<span style="font-family: Roboto Slabk"><b>Neighborhood : </b></span>%{y}'+'<br><span style="font-family: Roboto Slabk"><b>Year : </b></span>%{x}</br>'+'<span style="font-family: Roboto Slabk"><b>Trees planted : </b></span>%{z}<extra></extra>')

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>