Plotly
dyce.viz.plotly builds Plotly figure specifications for H objects.
Each builder returns a PlotSpec containing plain mappings and lists.
Neither Plotly nor Matplotlib is required.
Callers can pass spec.data, spec.layout, and spec.config to Plotly.newPlot, or pass spec.figure_dict() to plotly.graph_objects.Figure.
PlotSpec
dataclass
Portable structural description of a Plotly figure.
data and layout are accepted by both Plotly.py and Plotly.js.
config contains renderer options used by Plotly.js and by HTML generated with Plotly.py.
as_dict returns a plain, JSON-serializable representation suitable for crossing a worker boundary.
Source code in dyce/viz/plotly.py
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 | |
as_dict() -> dict[str, Any]
Return the complete specification as plain mappings and lists.
Source code in dyce/viz/plotly.py
71 72 73 | |
figure_dict() -> dict[str, Any]
Return the portion accepted by plotly.graph_objects.Figure.
Source code in dyce/viz/plotly.py
75 76 77 | |
bar_spec(*hs: H, colors: Sequence[str] = (), graph_type: GraphType = GraphType.NORMAL, horizontal: bool = False, labels: Sequence[str] = (), max_percent: float | None = None, precision: int = _DEFAULT_PRECISION) -> PlotSpec
Experimental
dyce.viz.plotly.bar_spec is experimental; its interface may change or it may be removed in a future release.
Return a portable Plotly figure specification for a grouped bar chart of one or more histograms.
Use labels to assign legend names to each histogram. Unmatched histograms receive an empty label.
colors assigns hues, cycling as needed.
graph_type controls which variant of the distribution is plotted (see GraphType).
When horizontal is True, outcomes appear on the y-axis and probabilities on the x-axis.
max_percent fixes the probability-axis maximum, which is useful for keeping several separately rendered figures comparable.
precision is the number of decimal places tooltips show.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Source code in dyce/viz/plotly.py
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 | |
line_spec(*hs: H, colors: Sequence[str] = (), graph_type: GraphType = GraphType.NORMAL, labels: Sequence[str] = (), precision: int = _DEFAULT_PRECISION) -> PlotSpec
Experimental
dyce.viz.plotly.line_spec is experimental; its interface may change or it may be removed in a future release.
Return a portable Plotly figure specification for a line graph of one or more histograms.
Use labels to assign legend names to each histogram. Unmatched histograms receive an empty label.
colors assigns hues, cycling as needed.
graph_type controls which variant of the distribution is plotted (see GraphType).
precision is the number of decimal places tooltips show.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
Source code in dyce/viz/plotly.py
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
ridge_spec(*hs: H, colors: Sequence[str] = (), graph_type: GraphType = GraphType.NORMAL, label_bgcolor: str | None = None, labels: Sequence[str] = (), overlap: float = _DEFAULT_RIDGE_OVERLAP, peak: float | None = None, precision: int = _DEFAULT_PRECISION) -> PlotSpec
Experimental
dyce.viz.plotly.ridge_spec is experimental; its interface may change or it may be removed in a future release.
Return a portable Plotly figure specification for a ridgeline (“joyplot”) of one or more histograms.
Each histogram becomes its own filled ridge, stacked vertically and offset so that neighbors overlap. Ridges appear top-to-bottom in argument order, and lower ridges are drawn in front of higher ones.
Each ridge covers only its own outcomes. Where a neighbor has an outcome this histogram lacks, the line bridges the gap rather than dipping to zero, since the histogram says nothing there rather than saying zero.
Every ridge contributes two traces, a translucent fill and an opaque crest line carrying the markers and the tooltip.
Each trace’s meta records its ridge and which of the two it is, so a caller can restyle without counting.
Use labels to name each histogram. Names are drawn as “pills” inside the plot at their ridge’s baseline, pinned to the left edge, so a long one grows rightward over its own ridge rather than clipping into the margin. Unmatched histograms get a blank label. Set label_bgcolor to a translucent color appropriate for the rendering context.
colors assigns a hue per ridge, cycled if there are fewer colors than histograms.
Each ridge’s fill takes that hue translucently and its crest line takes it at full strength.
Without colors, the traces carry none and Plotly’s own sequence gives a ridge’s fill and line different hues, so either supply colors or restyle by meta afterward.
graph_type controls which variant of the distribution is plotted (see GraphType).
overlap is how many rows tall a ridge at peak stands.
At 1.0, such a ridge just reaches the next row's baseline.
peak overrides the percentage drawn at full height, which is otherwise the largest among hs. Pass the largest across several figures to put them all on one scale, so ridges stay comparable between subplots.
precision is the number of decimal places tooltips show.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Source code in dyce/viz/plotly.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |