Visualization¶
Plotting helpers for designs, effects, diagnostics, and response surfaces.
Most ExperimentPlotter methods return a Matplotlib Figure; its
interactive_design_explorer is the exception and returns a Plotly
graph_objects.Figure. Every ResponseSurfacePlotter method returns a Plotly
figure, which is interactive in a notebook and supports .show() and
.write_html(). Either way the returned object can be customised before
display.
Experiment plots¶
industrialstats.visualizations.plots ¶
Visualization functions for experimental designs and analysis.
ExperimentPlotter ¶
Main plotting class for experimental designs and results.
Initialize the plotter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data with responses. |
None
|
design_matrix
|
DataFrame
|
Design matrix without responses. |
None
|
Source code in src/industrialstats/visualizations/plots.py
main_effects_plot ¶
Create a main-effects plot of factor level means.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_column
|
str
|
Column name of the response variable. |
required |
figsize
|
tuple of int
|
Figure size. Defaults to |
(12, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Generated main-effects plot. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is missing or response column is invalid. |
Source code in src/industrialstats/visualizations/plots.py
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 | |
design_comparison_plot
staticmethod
¶
design_comparison_plot(designs: dict[str, ExperimentalDesign], figsize: tuple[int, int] = (12, 8)) -> Figure
Compare multiple designs side by side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
designs
|
dict of str to ExperimentalDesign
|
Mapping of design names to design instances with generated design matrices. |
required |
figsize
|
tuple of int
|
Figure size for the plot grid. Defaults to |
(12, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Figure containing design space plots and a metrics table. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a design lacks a design matrix or has fewer than two factors. |
Examples:
>>> from industrialstats.designs.factorial import Factor, FactorialDesign
>>> from industrialstats.designs.rcbd import RandomizedCompleteBlockDesign
>>> fd = FactorialDesign([Factor("A", [0, 1]), Factor("B", [0, 1])])
>>> fd.generate_design()
>>> rcbd = RandomizedCompleteBlockDesign(["T1", "T2"], ["B1", "B2"])
>>> rcbd.generate_design()
>>> ExperimentPlotter.design_comparison_plot({"Factorial": fd, "RCBD": rcbd})
<Figure size ...>
Source code in src/industrialstats/visualizations/plots.py
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
interactive_design_explorer ¶
interactive_design_explorer(response_column: str | None = None, filename: str | None = None) -> Figure
Create an interactive design-space explorer using Plotly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_column
|
str
|
Column name of the response variable for color overlay. |
None
|
filename
|
str
|
Path to export the interactive plot as an HTML file. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
Generated interactive figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither data nor design matrix is available or fewer than two factors are present. |
Examples:
>>> from industrialstats.designs.factorial import Factor, FactorialDesign
>>> design = FactorialDesign([Factor("A", [0, 1]), Factor("B", [0, 1])])
>>> design.generate_design()
>>> plotter = ExperimentPlotter(design_matrix=design.design_matrix)
>>> fig = plotter.interactive_design_explorer()
>>> isinstance(fig, go.Figure)
True
Source code in src/industrialstats/visualizations/plots.py
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 379 380 381 382 383 384 385 386 387 | |
interaction_plot ¶
interaction_plot(factor1: str, factor2: str, response_column: str, figsize: tuple[int, int] = (10, 6)) -> Figure
Create an interaction plot between two factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor1
|
str
|
First factor name. |
required |
factor2
|
str
|
Second factor name. |
required |
response_column
|
str
|
Response variable name. |
required |
figsize
|
tuple of int
|
Figure size. Defaults to |
(10, 6)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Interaction plot figure. |
Source code in src/industrialstats/visualizations/plots.py
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
residual_plots ¶
Create comprehensive residual analysis plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_results
|
dict[str, ndarray]
|
Dictionary containing residuals, fitted values, etc. |
required |
figsize
|
tuple of int
|
Figure size. Defaults to |
(15, 10)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Residual analysis plots. |
Source code in src/industrialstats/visualizations/plots.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
design_space_plot ¶
design_space_plot(factor1: str, factor2: str, response_column: str | None = None, figsize: tuple[int, int] = (10, 8)) -> Figure
Create design space plot showing experimental points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor1
|
str
|
Factor for the x-axis. |
required |
factor2
|
str
|
Factor for the y-axis. |
required |
response_column
|
str
|
Response variable for color coding. |
None
|
figsize
|
tuple of int
|
Figure size. Defaults to |
(10, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Design space plot. |
Source code in src/industrialstats/visualizations/plots.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
factorial_cube_plot ¶
factorial_cube_plot(factors: list[str], response_column: str | None = None, figsize: tuple[int, int] = (10, 8)) -> Figure
Create 3D cube plot for 3-factor designs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factors
|
list[str]
|
List of exactly three factor names. |
required |
response_column
|
str
|
Response variable for color coding. |
None
|
figsize
|
tuple of int
|
Figure size. Defaults to |
(10, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
3D factorial cube plot. |
Source code in src/industrialstats/visualizations/plots.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | |
box_plots_by_factor ¶
Create box plots for each factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_column
|
str
|
Response variable name. |
required |
figsize
|
tuple of int
|
Figure size. Defaults to |
(15, 8)
|
Returns:
| Type | Description |
|---|---|
Figure
|
Box plots by factor. |
Source code in src/industrialstats/visualizations/plots.py
Response surface plots¶
industrialstats.visualizations.response_surface_plots ¶
Interactive response surface visualization tools.
This module provides the :class:ResponseSurfacePlotter class for generating
3D response surface plots, contour maps with optimization paths, prediction
variance surfaces, and slice plots at fixed factor levels. Plotly is used to
provide interactive figures that can be embedded in notebooks or exported to
HTML.
Examples:
>>> from industrialstats.designs.response_surface import ResponseSurfaceDesign, Factor
>>> import pandas as pd
>>> import statsmodels.formula.api as smf
>>> factors = [Factor("x1", [-1, 1]), Factor("x2", [-1, 1])]
>>> design = ResponseSurfaceDesign(factors)
>>> dm = design.generate_design()
>>> dm["y"] = dm["x1"] ** 2 + dm["x2"] ** 2
>>> model = smf.ols("y ~ x1 + x2 + I(x1**2) + I(x2**2) + x1:x2", data=dm).fit()
>>> plotter = ResponseSurfacePlotter(design, model)
>>> fig = plotter.surface_plot("x1", "x2")
>>> isinstance(fig.to_dict(), dict)
True
ResponseSurfacePlotter
dataclass
¶
ResponseSurfacePlotter(design: ResponseSurfaceDesign, model: Any)
Visualize fitted response surface models in three dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
design
|
ResponseSurfaceDesign
|
Generated response surface design containing factor ranges. |
required |
model
|
Any
|
Fitted model with a :meth: |
required |
surface_plot ¶
Plot a 3D response surface for two factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
str
|
Factor names for the x- and y-axes. |
required |
x2
|
str
|
Factor names for the x- and y-axes. |
required |
resolution
|
int
|
Number of grid points per axis. Defaults to |
50
|
Returns:
| Type | Description |
|---|---|
Figure
|
Interactive 3D surface plot. |
Source code in src/industrialstats/visualizations/response_surface_plots.py
contour_plot ¶
contour_plot(x1: str, x2: str, resolution: int = 50, path: Iterable[tuple[float, float]] | None = None) -> Figure
Create a contour plot with optional optimization path overlay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
str
|
Factor names for the axes. |
required |
x2
|
str
|
Factor names for the axes. |
required |
resolution
|
int
|
Grid resolution per axis. Defaults to |
50
|
path
|
iterable of tuple[float, float]
|
Sequence of (x1, x2) points representing an optimization path. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
Interactive contour plot. |
Source code in src/industrialstats/visualizations/response_surface_plots.py
prediction_variance_surface ¶
Visualize the prediction variance surface for two factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
str
|
Factor names for the axes. |
required |
x2
|
str
|
Factor names for the axes. |
required |
resolution
|
int
|
Grid resolution per axis. Defaults to |
50
|
Returns:
| Type | Description |
|---|---|
Figure
|
Surface plot of prediction variance. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the model does not provide prediction variance via
|
Source code in src/industrialstats/visualizations/response_surface_plots.py
slice_plot ¶
Plot model response by varying one factor with others fixed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
varying
|
str
|
Factor to vary along the x-axis. |
required |
fixed
|
dict[str, float]
|
Mapping of other factor names to fixed levels. |
required |
resolution
|
int
|
Number of points along the varying factor. Defaults to |
50
|
Returns:
| Type | Description |
|---|---|
Figure
|
Line plot showing the slice through the response surface. |