-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_options_cheats.py
207 lines (172 loc) · 7.03 KB
/
common_options_cheats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import plotly.express as px
import pandas as pd
# Specifying default templates for all subsequent plots
import plotly.io as pio
pio.templates.default= "plotly"
# if needed, import the data
df = pd.read_pickle("my_xp_results.pkl")
# which algorithm is more accurate? What is the impact of rank value?
fig = px.box(df, x='algorithm', y='final_rec_error',
title="Which algorithm is more accurate? Does rank have an impact?",
template="plotly_white", points="all", facet_col="rank_est",
color="algorithm", log_y=True)
# quick word: Plotly has a very confusing magic underscore syntax, so
# go.Layout(title=dict(font=dict(...))) is the same than
# go.Layout(title_font=dict(...))
# The same goes for things below, anytime an underscore is used,
# plotly actually understand updating a dictionary
# Updating layout (title, fonts, figsize, templates, backgrounds)
fig.update_layout(
# Check doc on plotly, update_layout. Actually quite clear but long
# Title things
title_font_size=25, # font size
title_text="C'est stylé", # title
title_x=.1, # position [0,1]
title_yanchor="bottom", # anchor position, ["top","middle","bottom","auto"]
# Legend things
showlegend=True,
legend_bgcolor="#eeeeee", # RBG, all formats accepted, here Hex
legend_bordercolor="#000000",
legend_borderwidth=2, # a bit useless
legend_font_size=20, # fonts always have these 3 options
legend_font_color="black",
legend_font_family="Comic Sans",
legend_title_font_size=10,
legend_title_text="Name of the Algorithm",
# To change the name of title for the legend
# in the px.plot call: labels={"sex": "Gender", "smoker": "Smokes"}
legend_x=-0.5, # x position in [-2,3] normalized so that borders are [0,1]
legend_y=0, # y position in [-2,3]
# Sizes of figure
width=800, # in px
height=600,
# Global font
font_color="#555555",
font_family="Courier New", # does not erase other specified fonts
# A few common font families
# Sans-serif fonts: Arial, Comic Sans MS, Trebuchet MS, and Verdana
# Serif fonts: Georgia and Times New Roman
# Monospace fonts: Andale Mono and Courier New
font_size=12,
# Backgrounds
paper_bgcolor="#dddddd",
plot_bgcolor="#abcdef",
# Colors
# 3 ways to specify the nodes values (diverging, sequential, sequential minus)
# not shown below
colorscale_diverging=[[0,"#051017"],[0.5,"#ffffff"],[1,"#000000"]],
colorway=["#ffffff","#1f77b4", "#000000"], # change default trace color values
# this updates the defaults colors, but traces have already been assigned colors
# more useful for templating
# Template
template="plotly_white", #['ggplot2', 'seaborn', 'simple_white', 'plotly',
#'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
#'ygridoff', 'gridon', 'none']
# Subplots
# We can use the update_xaxes or update_yaxis syntax, but this also works for a quick fix:
xaxis1=dict(range=[0,0.2], title_text="Time (s)"),
xaxis2=dict(range=[0,0.3], title_text="Time (s)"),
xaxis3=dict(range=[0,0.2]),
xaxis4=dict(range=[0,0.3]),
yaxis1=dict(title_text="Fit"),
yaxis3=dict(title_text="Fit")
)
# Axes
# for subplots: 1st subplot is layout_xaxis1, layout_xaxis2... but xaxes is all subplots
# subplot numbering is
# 3 4
# 1 2
fig.update_xaxes(
#documentation: update_xaxis
# axis line property
color="#ff0000", # changes all colors associated (lines, ticks, grids, text)
linecolor="#aa0123", # only the line axis color
linewidth=10,
showline=True,
type="category", # "-", "log","linear","category","date"
# Ticks things and grids
nticks=2, # number of ticks
#range=[0,1], # range of the ticks
# care for log, and category is mapped to ints (but does not show in this eg)
# Also affects yrange??
dtick=1, # distance between ticks, not so useful for category
showspikes=True, # shows the small tick lines
showticklabels=True,
tickcolor="#000000",
ticklen=5, # length of ticks in px
tickfont_size=8, # size of text of ticks, other txt options same format
# Changing the ticks text is a little bit of work
# first change ticks type to array, then update text and place them correctly
tickmode="array",
tickvals=[0,1], # list with the positions of the ticks
ticktext=["Aliens", "Me"],
# axes title
title_font_size=13, # same story as other fonts specs
title_text="", # always put name on axes !!
# grid
gridcolor="#ffffff",
gridwidth=1, # activates the grid for boxplot
showgrid=True, # overwrites above if False
# Numbers of the top/on the right (for y axis)
mirror=False, # True, "ticks", "all", "allticks", False
# decouple axes scales
#matches=False,
# misc
visible=True,
zeroline=False, # puts a line at 0
zerolinewidth=0
)
# Traces updates. Here we have a box trace, options are different? for line traces
fig.update_traces(
# documentation: update_traces
# Selection
#selector=3,
selector=dict(name="hals"), # use to select the trace being updated
# Default plotly express names: the name used for the legend, or numerics?
# To select all traces: selector=dict()
# To select all traces of a subplot: sounds like a bad idea
# name of the trace, also changes the legend
name="HaLs",
#showlegend=True, # shows legend or not for a single trace.
# will repeat legend if used for all subplots !!
# Trace appearence
opacity=0.5, # in [0,1], 1 is not actually 100%
width=0.8, # in data coordinate; for boxplots only
orientation="v", # v or h, boxplot only
# Marker things
marker_color="#000000", # also accepts color ranges for colormaps
# weirdly affects the box as well
marker_opacity=0.5, #only dots
marker_size=8, # in px
marker_symbol="bowtie", # large choice, check update trace doc
# for line plots, check marker_colorbar
# For error bars (works for assymetric as well)
#error_y_thickness = 0.2, # changes the width of error bars in line plots (and boxplots?)
# box things, also for line plots
line_color="#ff0000", # color of boxes (bounding lines, also changes inside)
fillcolor="#0000ff",
line_width=1,
# line_dash...
)
# annotations updates, mainly subplot titles.
# In principle, any non-standard piece of text in the plot
fig.update_annotations(
# documentation at update_annotations
font_size=14,
text="Best plot"
)
# To update annotations for each subplot, we can loop over annotations
# and manually edit (sigh...)
# an exemple for subplot titles:
for i, ann in enumerate(fig.layout.annotations):
ann.text="Plot_"+str(i)
# to add an annotation,
# fig.add_annotation()
# Adding shapes directly with figure methods
# Specify row and col for plotting in a specific subplot
fig.add_hline(y=0.5, line_dash="dot", row=1, col=1, line_color="#000000", line_width=2)
#############################
# Plotting
print(fig)
#
fig.show()