def __getitem__(self, item): if isinstance(item, string_types): template_names = item.split("+") else: template_names = [item] templates = [] for template_name in template_names: template = self._templates[template_name] if template is Lazy: from plotly.graph_objs.layout import Template if template_name == "none": # "none" is a special built-in named template that applied no defaults template = Template(data_scatter=[{}]) self._templates[template_name] = template else: # Load template from package data path = os.path.join("/usr/share/python3-plotly", "templates", template_name + ".json") template_str = '' with open(path, 'r') as f: template_str = f.read() template_dict = json.loads( template_str.encode('utf-8').decode('utf-8')) template = Template(template_dict) self._templates[template_name] = template templates.append(self._templates[template_name]) return self.merge_templates(*templates)
def __getitem__(self, item): if isinstance(item, string_types): template_names = item.split("+") else: template_names = [item] templates = [] for template_name in template_names: template = self._templates[template_name] if template is Lazy: from plotly.graph_objs.layout import Template if template_name == "none": # "none" is a special built-in named template that applied no defaults template = Template(data_scatter=[{}]) self._templates[template_name] = template else: # Load template from package data path = os.path.join("package_data", "templates", template_name + ".json") template_str = pkgutil.get_data("plotly", path).decode("utf-8") template_dict = json.loads(template_str) template = Template(template_dict) self._templates[template_name] = template templates.append(self._templates[template_name]) return self.merge_templates(*templates)
def merge_templates(self, *args): """ Merge a collection of templates into a single combined template. Templates are process from left to right so if multiple templates specify the same propery, the right-most template will take precedence. Parameters ---------- args: list of Template Zero or more template objects (or dicts with compatible properties) Returns ------- template: A combined template object Examples -------- >>> pio.templates.merge_templates( ... go.layout.Template(layout={'font': {'size': 20}}), ... go.layout.Template(data={'scatter': [{'mode': 'markers'}]}), ... go.layout.Template(layout={'font': {'family': 'Courier'}})) layout.Template({ 'data': {'scatter': [{'mode': 'markers', 'type': 'scatter'}]}, 'layout': {'font': {'family': 'Courier', 'size': 20}} }) """ if args: return reduce(self._merge_2_templates, args) else: from plotly.graph_objs.layout import Template return Template()
def presentation(): """ Template that increases the size of text and markers/lines for certain trace types """ # Create blank template template = Template() # Increase global font size by 1.5x (12->18) template.layout.font.size = 18 # Increase scatter markers and lines by 1.5x opts = {'marker': {'size': 9}, 'line': {'width': 3}} template.data.scatter = [opts] template.data.scattergl = [opts] template.data.scatter3d = [opts] template.data.scatterpolar = [opts] template.data.scatterpolargl = [opts] template.data.scatterternary = [opts] template.data.scattergeo = [opts] # Increase default height of table cells template.data.table = [{'header': {'height': 36}, 'cells': {'height': 30}}] return template
def _setup_template(n_colorway_colors=10, n_colorscale_colors=10): colorway = [ 'var(--colorway-{})'.format(i) for i in range(n_colorway_colors) ] colorscale = [ 'var(--colorscale-{})'.format(i) for i in range(n_colorscale_colors) ] ddk_template = Template({ 'layout': { 'colorscale': { 'sequential': list( map(list, (zip([ x / (len(colorscale) - 1) for x in list(range(len(colorscale))) ], colorscale)))) }, 'colorway': colorway, # This will be overridden in graphUtils.js; # setting it to 0 (instead of None) # so PX will know not to set it in-line (i.e. in figure). 'margin': { 't': 0 } } }) pio.templates.default = ddk_template
def presentation(): """ Template that increases the size of text and markers/lines for certain trace types """ # Create blank template template = Template() template.layout.xaxis.title.standoff = 15 template.layout.yaxis.title.standoff = 15 # Increase global font size by 1.5x (12->18) template.layout.font.size = 18 # Increase scatter markers and lines by 1.5x opts = {"marker": {"size": 9}, "line": {"width": 3}} template.data.scatter = [opts] template.data.scattergl = [opts] template.data.scatter3d = [opts] template.data.scatterpolar = [opts] template.data.scatterpolargl = [opts] template.data.scatterternary = [opts] template.data.scattergeo = [opts] # Increase default height of table cells template.data.table = [{"header": {"height": 36}, "cells": {"height": 30}}] # Automargin for pie chart template.data.pie = [{"automargin": True}] return template
def xgridoff(): """ Tempalate to disable x-grid by default """ # Create blank template template = Template() template.layout.xaxis.showgrid = False return template
def gridon(): """ Template to enable x and y-grid by default """ # Create blank template template = Template() template.layout.xaxis.showgrid = True template.layout.yaxis.showgrid = True return template
def __getitem__(self, item): template = self._templates[item] if template is Lazy: # Load template from package data path = os.path.join('package_data', 'templates', item + '.json') template_str = pkgutil.get_data('plotly', path).decode('utf-8') template_dict = json.loads(template_str) template = Template(template_dict) self._templates[item] = template return template
def __getitem__(self, item): template = self._templates[item] if template is Lazy: from plotly.graph_objs.layout import Template if item == "none": # "none" is a special built-in named template that applied no defaults template = Template() self._templates[item] = template else: # Load template from package data path = os.path.join("package_data", "templates", item + ".json") template_str = pkgutil.get_data("plotly", path).decode("utf-8") template_dict = json.loads(template_str) template = Template(template_dict) self._templates[item] = template return template
def ygridoff(): """ Template to disable y-grid by default """ # Create blank template template = Template() template.layout.yaxis.showgrid = False # Automargin for pie chart template.data.pie = [{"automargin": True}] return template
def xgridoff(): """ Template to disable x-grid by default """ # Create blank template template = Template() template.layout.xaxis.showgrid = False template.layout.xaxis.title.standoff = 15 template.layout.yaxis.title.standoff = 15 # Automargin for pie chart template.data.pie = [{"automargin": True}] return template
def plotly_v4_colors(): template = Template() # Plasma colorscale # ----------------- # Get this from plotly_express logic after integration colorscale = [ "#0d0887", "#46039f", "#7201a8", "#9c179e", "#bd3786", "#d8576b", "#ed7953", "#fb9f3a", "#fdca26", "#f0f921", ] d = len(colorscale) - 1 colorscale = [ [(1.0 * i) / (1.0 * d), x] for i, x in enumerate(colorscale) ] template.layout.colorscale.sequential = colorscale template.data.heatmap = [dict(colorscale = colorscale)] template.data.histogram2d = [dict(colorscale = colorscale)] template.data.histogram2dcontour = [dict(colorscale = colorscale)] template.data.contour = [dict(colorscale = colorscale)] colorway = [ plotly_clrs['Cornflower'], plotly_clrs['Sienna'], plotly_clrs['Emerald'], plotly_clrs['Lavender Shade'], '#FFA15A', plotly_clrs['Aqua Shade'], '#FF6692', '#B6E880', '#FF97FF', '#FECB52' ] template.layout.colorway = colorway return template
def __getitem__(self, item): template = self._templates[item] if template is Lazy: from plotly.graph_objs.layout import Template # Load template from package data path = os.path.join('package_data', 'templates', item + '.json') template_str = pkgutil.get_data('plotly', path).decode('utf-8') template_dict = json.loads(template_str) template = Template(template_dict) if ('template_defaults' in _future_flags and isinstance(item, string_types) and item in ('plotly', 'plotly_white', 'plotly_dark')): template = self.merge_templates(template, self['plotly_v4_colors']) self._templates[item] = template return template
def _setup_template(n_colorway_colors=10, n_colorscale_colors=10): colorway = [ 'var(--colorway-{})'.format(i) for i in range(n_colorway_colors) ] colorscale = [ 'var(--colorscale-{})'.format(i) for i in range(n_colorscale_colors) ] ddk_template = Template({ 'layout': { 'colorscale': { 'sequential': list( map(list, (zip([ x / (len(colorscale) - 1) for x in list(range(len(colorscale))) ], colorscale)))) }, 'colorway': colorway, } }) pio.templates.default = ddk_template