plotter
frequenz.lib.notebooks.reporting.plotter ¤
Plotting functions for the reporting module.
Functions:¤
frequenz.lib.notebooks.reporting.plotter.plot_energy_pie_chart ¤
Create an interactive donut (pie) chart of energy sources.
Generates a pie chart showing the relative energy contributions from different sources (e.g., PV, grid, CHP), with percentage labels and hover details in kilowatt-hours.
| PARAMETER | DESCRIPTION |
|---|---|
power_df
|
DataFrame containing at least two columns:
-
TYPE:
|
color_dict
|
Optional dictionary mapping energy sources (Energiebezug) to custom color hex codes or rgba strings. If not provided, Plotly's default color sequence is used. |
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
A Plotly Figure object representing a donut-style energy distribution chart. |
Source code in src/frequenz/lib/notebooks/reporting/plotter.py
frequenz.lib.notebooks.reporting.plotter.plot_time_series ¤
plot_time_series(
df: DataFrame,
time_col: str | None = None,
cols: list[str] | None = None,
title: str = "Time Series Plot",
xaxis_title: str = "Timestamp",
yaxis_title: str = "kW",
legend_title: str | None = "",
color_dict: dict[str, str] | None = None,
long_format_flag: bool = False,
category_col: str | None = None,
value_col: str | None = None,
fill_cols: list[str] | None = None,
dotted_cols: list[str] | None = None,
plot_order: list[str] | None = None,
shade_by_category: bool = False,
secondary_y_cols: Sequence[str] | None = None,
secondary_y_title: str | None = None,
date_range_selector_position: (
dict[str, object] | None
) = None,
legend_position: dict[str, object] | None = None,
legend_max_height: int | float | None = 70,
top_margin: int = 160,
) -> Figure
Create an interactive time-series plot using Plotly.
Generates a multi-line time-series plot from a DataFrame, optionally handling long-to-wide data transformations and area fills for selected columns. The plot includes zoom controls, a range slider, and a date range selector.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Input DataFrame containing time and numeric data.
TYPE:
|
time_col
|
Name of the timestamp column to use as the x-axis. If None, the current index is used.
TYPE:
|
cols
|
List of numeric columns to plot. If None, all numeric columns
except |
title
|
Plot title displayed at the top. Defaults to "Time Series Plot".
TYPE:
|
xaxis_title
|
Label for the x-axis. Defaults to "Timestamp".
TYPE:
|
yaxis_title
|
Label for the y-axis. Defaults to "kW".
TYPE:
|
legend_title
|
Title for the legend. Defaults to "Components".
TYPE:
|
color_dict
|
Optional dictionary mapping column names to custom colors. If not provided, default Plotly colors are used. |
long_format_flag
|
Whether to convert the DataFrame from long to wide format before plotting. Defaults to False.
TYPE:
|
category_col
|
Column name for categories when converting from long to
wide format. Used only if
TYPE:
|
value_col
|
Column name for values when converting from long to wide
format. Used only if
TYPE:
|
fill_cols
|
List of column names to plot as filled areas under the curve. Defaults to None (no fill). |
dotted_cols
|
List of column names to render with dotted lines. Defaults to None (no dotted lines). |
plot_order
|
Optional list specifying the order of columns to plot. If None,
the order in |
shade_by_category
|
When plotting a long-format series, render all categories as different shades of the same base color.
TYPE:
|
secondary_y_cols
|
Optional plotted columns to render on a secondary y-axis. |
secondary_y_title
|
Optional title for the secondary y-axis. Defaults to
TYPE:
|
date_range_selector_position
|
Optional Plotly range selector positioning
options, for example |
legend_position
|
Optional Plotly legend positioning options, for example
|
legend_max_height
|
Maximum legend height in pixels, or a layout-height ratio when less than or equal to 1. Plotly shows an independent legend scrollbar when entries exceed this height. Set to None to use Plotly's default legend height. |
top_margin
|
Top layout margin in pixels. Increase this when placing the date range selector and legend above the plot.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
A Plotly Figure object representing the interactive time-series plot. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If |
Source code in src/frequenz/lib/notebooks/reporting/plotter.py
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 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 379 380 381 382 383 384 385 386 387 388 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 475 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 | |
frequenz.lib.notebooks.reporting.plotter.plot_time_series_battery_soc ¤
plot_time_series_battery_soc(
df: DataFrame,
time_col: str | None = None,
title: str = "Battery Charge/Discharge and SOC",
xaxis_title: str = "Timestamp",
yaxis_title: str = "kW",
legend_title: str | None = "Components",
color_dict: dict[str, str] | None = None,
battery_power_flow: str = "battery_power_flow",
soc_pct: str = "soc",
secondary_y_title: str = "SOC [%]",
date_range_selector_position: (
dict[str, object] | None
) = None,
legend_position: dict[str, object] | None = None,
legend_max_height: int | float | None = 70,
top_margin: int = 160,
) -> Figure
Plot battery charging, discharging, and SOC over time.
This is a focused adapter around :func:plot_time_series: battery charging
and discharging are rendered on the primary y-axis, while SOC percentage is
rendered on the secondary y-axis. The adapter only normalizes input column
names and defaults; all layout, hover, legend, range selector, and secondary
axis behavior comes from :func:plot_time_series.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Source DataFrame containing battery charging, discharging, and SOC.
TYPE:
|
time_col
|
Optional timestamp column to use as the x-axis.
TYPE:
|
title
|
Plot title.
TYPE:
|
xaxis_title
|
X-axis label.
TYPE:
|
yaxis_title
|
Primary y-axis label for charging/discharging.
TYPE:
|
legend_title
|
Legend title.
TYPE:
|
color_dict
|
Optional color mapping for display trace names. |
battery_power_flow
|
Column containing battery power flow values. Used to derive charging and discharging. Positive values are charging and negative values are discharging.
TYPE:
|
soc_pct
|
Column containing SOC percentage values.
TYPE:
|
secondary_y_title
|
Secondary y-axis label for SOC.
TYPE:
|
date_range_selector_position
|
Optional Plotly range selector positioning
options forwarded to :func: |
legend_position
|
Optional Plotly legend positioning options forwarded to
:func: |
legend_max_height
|
Maximum legend height forwarded to
:func: |
top_margin
|
Top layout margin in pixels forwarded to
:func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
A Plotly figure with battery power on the primary y-axis and SOC on the |
Figure
|
secondary y-axis. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If any configured input column is missing. |
Source code in src/frequenz/lib/notebooks/reporting/plotter.py
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 577 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 | |
frequenz.lib.notebooks.reporting.plotter.plot_time_series_battery_soc_and_usecase ¤
plot_time_series_battery_soc_and_usecase(
df: DataFrame,
time_col: str | None = None,
cols: list[str] | None = None,
title: str = "Battery Charge/Discharge and SOC",
xaxis_title: str = "Timestamp",
yaxis_title: str = "kW",
legend_title: str | None = "Components",
color_dict: dict[str, str] | None = None,
long_format_flag: bool = False,
category_col: str | None = None,
value_col: str | None = None,
fill_cols: list[str] | None = None,
dotted_cols: list[str] | None = None,
plot_order: list[str] | None = None,
shade_by_category: bool = False,
battery_power_flow: str = "battery_power_flow",
battery_charging: str = "battery_discharge",
battery_discharging: str = "battery_charge",
pv_col: str = "pv",
consumption_col: str = "mid_consumption",
grid_consumption: str = "grid_consumption",
stack_mode: BatteryUsecaseStackMode = "psc",
soc_pct: str = "soc",
soc_secondary_y_title: str = "SOC [%]",
secondary_y_cols: Sequence[str] | None = None,
secondary_y_title: str | None = None,
date_range_selector_position: (
dict[str, object] | None
) = None,
legend_position: dict[str, object] | None = None,
legend_max_height: int | float | None = 70,
top_margin: int = 160,
) -> Figure
Plot SOC and battery-usecase views with buttons to switch between them.
This accepts the same battery-usecase options as
:func:plot_time_series_battery_usecase. The secondary_y_cols and
secondary_y_title options apply to the battery-usecase view, while
soc_secondary_y_title applies to the SOC view.
Source code in src/frequenz/lib/notebooks/reporting/plotter.py
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 671 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 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
frequenz.lib.notebooks.reporting.plotter.plot_time_series_battery_usecase ¤
plot_time_series_battery_usecase(
df: DataFrame,
time_col: str | None = None,
cols: list[str] | None = None,
title: str = "Time Series Plot",
xaxis_title: str = "Timestamp",
yaxis_title: str = "kW",
legend_title: str | None = "Components",
color_dict: dict[str, str] | None = None,
long_format_flag: bool = False,
category_col: str | None = None,
value_col: str | None = None,
fill_cols: list[str] | None = None,
dotted_cols: list[str] | None = None,
plot_order: list[str] | None = None,
shade_by_category: bool = False,
battery_power_flow: str = "battery_power_flow",
battery_charging: str = "battery_discharge",
battery_discharging: str = "battery_charge",
pv_col: str = "pv",
consumption_col: str = "mid_consumption",
grid_consumption: str = "grid_consumption",
stack_mode: BatteryUsecaseStackMode = "psc",
secondary_y_cols: Sequence[str] | None = None,
secondary_y_title: str | None = None,
date_range_selector_position: (
dict[str, object] | None
) = None,
legend_position: dict[str, object] | None = None,
legend_max_height: int | float | None = 70,
top_margin: int = 160,
) -> Figure
Plot a battery-usecase time series with charge/discharge overlays.
Builds a reporting plot for battery-usecase analysis by combining the standard time-series traces with dedicated filled overlays for battery charging and discharging with selectable legacy/current stacking.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Source DataFrame containing the battery-usecase time series.
TYPE:
|
time_col
|
Optional timestamp column to use as the x-axis.
TYPE:
|
cols
|
Optional columns to plot. |
title
|
Plot title.
TYPE:
|
xaxis_title
|
X-axis label.
TYPE:
|
yaxis_title
|
Primary y-axis label.
TYPE:
|
legend_title
|
Legend title.
TYPE:
|
color_dict
|
Optional color mapping for traces. |
long_format_flag
|
Whether
TYPE:
|
category_col
|
Category column name for long-format inputs.
TYPE:
|
value_col
|
Value column name for long-format inputs.
TYPE:
|
fill_cols
|
Columns to render as filled traces. |
dotted_cols
|
Columns to render with dotted lines. |
plot_order
|
Optional explicit trace order. |
shade_by_category
|
Whether to generate color shades by category.
TYPE:
|
battery_power_flow
|
Column containing battery power flow values.
TYPE:
|
battery_charging
|
Column containing the battery charging series.
TYPE:
|
battery_discharging
|
Column containing the battery discharging series.
TYPE:
|
pv_col
|
Column containing PV production values.
TYPE:
|
consumption_col
|
Column containing site consumption. Defaults to
TYPE:
|
grid_consumption
|
Column containing grid consumption with battery support.
TYPE:
|
stack_mode
|
Overlay style selector.
TYPE:
|
secondary_y_cols
|
Optional columns to render on the secondary y-axis. |
secondary_y_title
|
Secondary y-axis label.
TYPE:
|
date_range_selector_position
|
Optional Plotly range selector positioning
options forwarded to :func: |
legend_position
|
Optional Plotly legend positioning options forwarded to
:func: |
legend_max_height
|
Maximum legend height forwarded to
:func: |
top_margin
|
Top layout margin in pixels forwarded to
:func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
A Plotly figure for battery-usecase analysis. |
Source code in src/frequenz/lib/notebooks/reporting/plotter.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |