Skip to content

Commit

Permalink
Merge pull request #1864 from joelostblom/mpl-template
Browse files Browse the repository at this point in the history
Add mpl-like template
  • Loading branch information
nicolaskruchten authored Nov 7, 2019
2 parents 5830055 + 6765ade commit 643f58e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/python/plotly/plotly/io/_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self):
default_templates = [
"ggplot2",
"seaborn",
"simple_white",
"plotly",
"plotly_white",
"plotly_dark",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"layout": {"colorway": ["#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", "#9467BD", "#8C564B", "#E377C2", "#7F7F7F", "#BCBD22", "#17BECF"], "font": {"color": "rgb(36,36,36)"}, "hovermode": "closest", "hoverlabel": {"align": "left"}, "paper_bgcolor": "white", "plot_bgcolor": "white", "polar": {"bgcolor": "white", "angularaxis": {"gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside"}, "radialaxis": {"gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside"}}, "ternary": {"bgcolor": "white", "aaxis": {"gridcolor": "#DFE8F3", "linecolor": "#A2B1C6", "showgrid": false, "showline": true, "ticks": "outside"}, "baxis": {"gridcolor": "#DFE8F3", "linecolor": "#A2B1C6", "showgrid": false, "showline": true, "ticks": "outside"}, "caxis": {"gridcolor": "#DFE8F3", "linecolor": "#A2B1C6", "showgrid": false, "showline": true, "ticks": "outside"}}, "colorscale": {"sequential": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]], "sequentialminus": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]], "diverging": [[0.0, "rgb(103,0,31)"], [0.1, "rgb(178,24,43)"], [0.2, "rgb(214,96,77)"], [0.3, "rgb(244,165,130)"], [0.4, "rgb(253,219,199)"], [0.5, "rgb(247,247,247)"], [0.6, "rgb(209,229,240)"], [0.7, "rgb(146,197,222)"], [0.8, "rgb(67,147,195)"], [0.9, "rgb(33,102,172)"], [1.0, "rgb(5,48,97)"]]}, "xaxis": {"gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "zerolinecolor": "rgb(36,36,36)", "automargin": true, "zeroline": false}, "yaxis": {"gridcolor": "rgb(232,232,232)", "linecolor": "rgb(36,36,36)", "showgrid": false, "showline": true, "ticks": "outside", "zerolinecolor": "rgb(36,36,36)", "automargin": true, "zeroline": false}, "scene": {"xaxis": {"backgroundcolor": "white", "gridcolor": "#DFE8F3", "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zerolinecolor": "rgb(36,36,36)", "gridwidth": 2, "zeroline": false}, "yaxis": {"backgroundcolor": "white", "gridcolor": "#DFE8F3", "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zerolinecolor": "rgb(36,36,36)", "gridwidth": 2, "zeroline": false}, "zaxis": {"backgroundcolor": "white", "gridcolor": "#DFE8F3", "linecolor": "rgb(36,36,36)", "showbackground": true, "showgrid": false, "showline": true, "ticks": "outside", "zerolinecolor": "rgb(36,36,36)", "gridwidth": 2, "zeroline": false}}, "shapedefaults": {"fillcolor": "black", "line": {"width": 0}, "opacity": 0.3}, "annotationdefaults": {"arrowhead": 0, "arrowwidth": 1}, "geo": {"bgcolor": "white", "landcolor": "white", "subunitcolor": "white", "showland": true, "showlakes": true, "lakecolor": "white"}, "title": {"x": 0.05}, "mapbox": {"style": "light"}}, "data": {"histogram2dcontour": [{"type": "histogram2dcontour", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "choropleth": [{"type": "choropleth", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}], "histogram2d": [{"type": "histogram2d", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "heatmap": [{"type": "heatmap", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "heatmapgl": [{"type": "heatmapgl", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "contourcarpet": [{"type": "contourcarpet", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}], "contour": [{"type": "contour", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "surface": [{"type": "surface", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}, "colorscale": [[0.0, "#440154"], [0.1111111111111111, "#482878"], [0.2222222222222222, "#3e4989"], [0.3333333333333333, "#31688e"], [0.4444444444444444, "#26828e"], [0.5555555555555556, "#1f9e89"], [0.6666666666666666, "#35b779"], [0.7777777777777778, "#6ece58"], [0.8888888888888888, "#b5de2b"], [1.0, "#fde725"]]}], "mesh3d": [{"type": "mesh3d", "colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}], "scatter": [{"type": "scatter", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "parcoords": [{"type": "parcoords", "line": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scatterpolargl": [{"type": "scatterpolargl", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "bar": [{"error_x": {"color": "rgb(36,36,36)"}, "error_y": {"color": "rgb(36,36,36)"}, "marker": {"line": {"color": "white", "width": 0.5}}, "type": "bar"}], "scattergeo": [{"type": "scattergeo", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scatterpolar": [{"type": "scatterpolar", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "histogram": [{"marker": {"line": {"color": "white", "width": 0.6}}, "type": "histogram"}], "scattergl": [{"type": "scattergl", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scatter3d": [{"type": "scatter3d", "line": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}, "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scattermapbox": [{"type": "scattermapbox", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scatterternary": [{"type": "scatterternary", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "scattercarpet": [{"type": "scattercarpet", "marker": {"colorbar": {"outlinewidth": 10, "tickcolor": "rgb(36,36,36)", "ticklen": 8, "ticks": "outside", "tickwidth": 2}}}], "carpet": [{"aaxis": {"endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)"}, "baxis": {"endlinecolor": "rgb(36,36,36)", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "rgb(36,36,36)"}, "type": "carpet"}], "table": [{"cells": {"fill": {"color": "rgb(237,237,237)"}, "line": {"color": "white"}}, "header": {"fill": {"color": "rgb(217,217,217)"}, "line": {"color": "white"}}, "type": "table"}], "barpolar": [{"marker": {"line": {"color": "white", "width": 0.5}}, "type": "barpolar"}]}}
77 changes: 77 additions & 0 deletions packages/python/plotly/templategen/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from templategen.utils import initialize_template
from .utils.colors import colors
import colorcet as cc
import plotly.express as px

# dict of template builder functions
# This way we can loop over definitions in __init__.py
Expand Down Expand Up @@ -73,6 +74,82 @@ def ggplot2():
builders["ggplot2"] = ggplot2


def simple_white():
# Set colorbar_common
colorbar_common = dict(
outlinewidth=10,
tickcolor=colors["gray14"],
ticks="outside",
tickwidth=2,
ticklen=8,
)

# Common axis common properties
axis_common = dict(
showgrid=False,
gridcolor=colors["gray91"],
linecolor=colors["gray14"],
ticks="outside",
showline=True,
)
# semi-transparent black and no outline
shape_defaults = dict(fillcolor="black", line={"width": 0}, opacity=0.3)

# Remove arrow head and make line thinner
annotation_defaults = {"arrowhead": 0, "arrowwidth": 1}

template = initialize_template(
paper_clr="white",
font_clr=colors["gray14"],
panel_background_clr="white",
panel_grid_clr="white",
axis_ticks_clr=colors["gray14"],
zerolinecolor_clr=colors["gray14"],
table_cell_clr=colors["gray93"],
table_header_clr=colors["gray85"],
table_line_clr="white",
colorway=px.colors.qualitative.D3,
colorbar_common=colorbar_common,
colorscale=px.colors.sequential.Viridis,
colorscale_diverging=px.colors.diverging.RdBu,
axis_common=axis_common,
annotation_defaults=annotation_defaults,
shape_defaults=shape_defaults,
)

# Left align title
template.layout.title.x = 0.05

# Increase grid width for 3d plots
opts = dict(gridwidth=2, gridcolor=plotly_clrs["gray91"], zeroline=False)
template.layout.scene.xaxis.update(opts)
template.layout.scene.yaxis.update(opts)
template.layout.scene.zaxis.update(opts)

# Darken ternary
opts = dict(linecolor=plotly_clrs["gray14"], gridcolor=plotly_clrs["gray91"])
template.layout.ternary.aaxis.update(opts)
template.layout.ternary.baxis.update(opts)
template.layout.ternary.caxis.update(opts)

# Remove lines through the origin
template.layout.xaxis.update(zeroline=False)
template.layout.yaxis.update(zeroline=False)

# Separate histogram bins wit ha white line
opts = {"marker": {"line": {"width": 0.6, "color": "white"}}}
template.data.histogram = [opts]

# Mapbox light style
template.layout.mapbox.style = "light"

# Set table header font color to white
return template


builders["simple_white"] = simple_white


def seaborn():
# Define colors
# -------------
Expand Down

0 comments on commit 643f58e

Please sign in to comment.