|
2 | 2 | from templategen.utils import initialize_template
|
3 | 3 | from .utils.colors import colors
|
4 | 4 | import colorcet as cc
|
| 5 | +import plotly.express as px |
5 | 6 |
|
6 | 7 | # dict of template builder functions
|
7 | 8 | # This way we can loop over definitions in __init__.py
|
@@ -73,6 +74,96 @@ def ggplot2():
|
73 | 74 | builders["ggplot2"] = ggplot2
|
74 | 75 |
|
75 | 76 |
|
| 77 | +def mpl(): |
| 78 | + # Set colorbar_common |
| 79 | + colorbar_common = dict( |
| 80 | + outlinewidth=10, |
| 81 | + tickcolor=colors["gray14"], |
| 82 | + ticks="outside", |
| 83 | + tickwidth=2, |
| 84 | + ticklen=8, |
| 85 | + ) |
| 86 | + |
| 87 | + # Common axis common properties |
| 88 | + axis_common = dict( |
| 89 | + showgrid=False, |
| 90 | + gridcolor=plotly_clrs["Rhino Light 2"], |
| 91 | + linecolor=colors["gray14"], |
| 92 | + ticks="outside", |
| 93 | + showline=True, |
| 94 | + ) |
| 95 | + |
| 96 | + # semi-transparent black and no outline |
| 97 | + # annotation_clr = "rgb(67,103,167)" |
| 98 | + # shape_defaults = dict(fillcolor=annotation_clr, line={"width": 0}, opacity=0.5) |
| 99 | + # Near black line color, no fill |
| 100 | + annotation_clr = plotly_clrs["Rhino Core"] |
| 101 | + shape_defaults = dict(line_color=annotation_clr) |
| 102 | + |
| 103 | + # Remove arrow head and make line thinner |
| 104 | + # annotation_defaults = {"arrowcolor": annotation_clr} |
| 105 | + |
| 106 | + # Remove arrow head and make line thinner |
| 107 | + annotation_defaults = { |
| 108 | + "arrowcolor": annotation_clr, |
| 109 | + "arrowhead": 0, |
| 110 | + "arrowwidth": 1, |
| 111 | + } |
| 112 | + |
| 113 | + template = initialize_template( |
| 114 | + paper_clr="white", |
| 115 | + font_clr=colors["gray14"], |
| 116 | + panel_background_clr="white", |
| 117 | + panel_grid_clr="white", |
| 118 | + axis_ticks_clr=colors["gray14"], |
| 119 | + zerolinecolor_clr=colors["gray14"], |
| 120 | + table_cell_clr="white", |
| 121 | + table_header_clr="white", |
| 122 | + table_line_clr="white", |
| 123 | + colorway=px.colors.qualitative.D3, |
| 124 | + colorbar_common=colorbar_common, |
| 125 | + colorscale=px.colors.sequential.Viridis, |
| 126 | + colorscale_diverging=px.colors.diverging.RdBu, |
| 127 | + axis_common=axis_common, |
| 128 | + annotation_defaults=annotation_defaults, |
| 129 | + shape_defaults=shape_defaults, |
| 130 | + ) |
| 131 | + |
| 132 | + # Left align title |
| 133 | + template.layout.title.x = 0.05 |
| 134 | + |
| 135 | + # Increase grid width for 3d plots |
| 136 | + opts = dict(gridwidth=2, gridcolor=plotly_clrs["Rhino Light 1"], zeroline=False) |
| 137 | + template.layout.scene.xaxis.update(opts) |
| 138 | + template.layout.scene.yaxis.update(opts) |
| 139 | + template.layout.scene.zaxis.update(opts) |
| 140 | + |
| 141 | + # Darken ternary |
| 142 | + opts = dict( |
| 143 | + linecolor=plotly_clrs["Rhino Medium 1"], gridcolor=plotly_clrs["Rhino Light 1"] |
| 144 | + ) |
| 145 | + template.layout.ternary.aaxis.update(opts) |
| 146 | + template.layout.ternary.baxis.update(opts) |
| 147 | + template.layout.ternary.caxis.update(opts) |
| 148 | + |
| 149 | + # Remove lines through the origin |
| 150 | + template.layout.xaxis.update(zeroline=False) |
| 151 | + template.layout.yaxis.update(zeroline=False) |
| 152 | + |
| 153 | + # Separate histogram bins wit ha white line |
| 154 | + opts = {"marker": {"line": {"width": 1, "color": "white"}}} |
| 155 | + template.data.histogram = [opts] |
| 156 | + |
| 157 | + # Mapbox light style |
| 158 | + template.layout.mapbox.style = "light" |
| 159 | + |
| 160 | + # Set table header font color to white |
| 161 | + return template |
| 162 | + |
| 163 | + |
| 164 | +builders["mpl"] = mpl |
| 165 | + |
| 166 | + |
76 | 167 | def seaborn():
|
77 | 168 | # Define colors
|
78 | 169 | # -------------
|
|
0 commit comments