Skip to content

feat: support custom colors (Series/dict) in plot_plotly and fix load… - #639

Open
nader-00 wants to merge 9 commits into
devfrom
383-custom-plot-colors-Feature
Open

feat: support custom colors (Series/dict) in plot_plotly and fix load…#639
nader-00 wants to merge 9 commits into
devfrom
383-custom-plot-colors-Feature

Conversation

@nader-00

@nader-00 nader-00 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR extends edisgo.tools.plots.plot_plotly to support custom colors for lines and nodes.

What changed

  • line_color now accepts, in addition to existing string options, a pandas.Series or dict
    mapping branch_name → color (e.g. "red", "#ff0000").
  • node_color now accepts, in addition to existing string options, a pandas.Series or dict
    mapping bus_name → color.
  • For custom colors:
    • Colors are taken directly from the provided Series/dict.
    • Lines/nodes that are not present in the Series/dict fall back to a default grey color.
    • No colorbar is shown (only explicit colors are used).
  • Existing behaviour for string options ("loading", "relative_loading", "reinforce",
    "voltage_deviation", "adjacencies") is unchanged.

Fixes #385

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • New and adjusted code is formatted using the pre-commit hooks
  • New and adjusted code includes type hinting now
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The Read the Docs documentation is compiling correctly
  • If new packages are needed, I added them the setup.py, and if needed the rtd_requirements.txt, the eDisGo_env.yml and the eDisGo_env_dev.yml.
  • I have added new features to the corresponding whatsnew file

Usage examples

import pandas as pd
from edisgo.tools import plots

# Example: color two specific lines
line_colors = pd.Series({
    "line_1": "red",
    "line_2": "orange",
})

# Example: color some buses
node_colors = {
    "bus_1": "blue",
    "bus_5": "purple",
}

fig = plots.plot_plotly(
    edisgo_obj,
    line_color=line_colors,
    node_color=node_colors,
    plot_map=False,
)

nader-00 and others added 9 commits June 3, 2026 15:30
… scaling

- plot_plotly accepts pd.Series or dict for line_color/node_color
- unmatched elements fall back to grey
- string-based options guarded with isinstance checks
- timeseries: scale loads by p_set instead of annual_consumption
… annual_consumption

- Allow pd.Series or dict for line_color and node_color in plot_plotly,
  falling back to grey for unmatched elements
- Add tests for custom color inputs in test_plots.py
- Revert predefined_conventional_loads_by_sector to scale by annual_consumption
  (p_set scaling was incorrect per supervisor feedback)
- Update test_timeseries.py assertions to match annual_consumption scaling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Improve plotting

2 participants