Skip to content

Commit feb0ced

Browse files
authored
Feature/plotting kwargs and streamline data conversion (#439)
* Feature/398 feature facet plots in results (#419) * Add animation and faceting options to plots * Adjust size of the frame * Utilize plotly express directly * Rmeocve old class * Use plotly express and modify stackgroup afterwards * Add modifications also to animations * Mkae more compact * Remove height stuff * Remove line and make set opacity =0 for area * Integrate faceting and animating into existing with_plotly method * Improve results.py * Improve results.py * Move check if dims are found to plotting.py * Fix usage of indexer * Change selection string with indexer * Change behaviout of parameter "indexing" * Update CHANGELOG.md * Add new selection parameter to plotting methods * deprectae old indexer parameter * deprectae old indexer parameter * Add test * Add test * Add test * Add test * Fix not supportet check for matplotlib * Typo in CHANGELOG.md * Feature/398 feature facet plots in results heatmaps (#418) * Add animation and faceting options to plots * Adjust size of the frame * Utilize plotly express directly * Rmeocve old class * Use plotly express and modify stackgroup afterwards * Add modifications also to animations * Mkae more compact * Remove height stuff * Remove line and make set opacity =0 for area * Integrate faceting and animating into existing with_plotly method * Improve results.py * Improve results.py * Move check if dims are found to plotting.py * Fix usage of indexer * Change selection string with indexer * Change behaviout of parameter "indexing" * Update CHANGELOG.md * Add new selection parameter to plotting methods * deprectae old indexer parameter * deprectae old indexer parameter * Add test * Add test * Add test * Add test * Add heatmap support * Unify to a single heatmap method per engine * Change defaults * readd time reshaping * readd time reshaping * lengthen scenario example * Update * Improve heatmap plotting * Improve heatmap plotting * Moved reshaping to plotting.py * COmbinations are possible! * Improve 'auto'behavioour * Improve 'auto' behavioour * Improve 'auto' behavioour * Allow multiple variables in a heatmap * Update modeule level plot_heatmap() * remove code duplication * Allow Dataset instead of List of DataArrays * Allow Dataset instead of List of DataArrays * Update plot tests * FIx Missing renme in ElementResults.plot_heatmap() * Update API * Feature/398 feature facet plots in results charge state (#417) * Add animation and faceting options to plots * Adjust size of the frame * Utilize plotly express directly * Rmeocve old class * Use plotly express and modify stackgroup afterwards * Add modifications also to animations * Mkae more compact * Remove height stuff * Remove line and make set opacity =0 for area * Integrate faceting and animating into existing with_plotly method * Improve results.py * Improve results.py * Move check if dims are found to plotting.py * Fix usage of indexer * Change selection string with indexer * Change behaviout of parameter "indexing" * Update CHANGELOG.md * Add new selection parameter to plotting methods * deprectae old indexer parameter * deprectae old indexer parameter * Add test * Add test * Add test * Add test * Add heatmap support * Unify to a single heatmap method per engine * Change defaults * readd time reshaping * readd time reshaping * lengthen scenario example * Update * Improve heatmap plotting * Improve heatmap plotting * Moved reshaping to plotting.py * COmbinations are possible! * Improve 'auto'behavioour * Improve 'auto' behavioour * Improve 'auto' behavioour * Allow multiple variables in a heatmap * Update modeule level plot_heatmap() * remove code duplication * Allow Dataset instead of List of DataArrays * Allow Dataset instead of List of DataArrays * Add tests * More examples * Update plot_charge state() * Try 1 * Try 2 * Add more examples * Add more examples * Add smooth line for charge state and use "area" as default * Update scenario_example.py * Update tests * Fix Error handling in plot_heatmap() * Feature/398 feature facet plots in results pie (#421) * Add animation and faceting options to plots * Adjust size of the frame * Utilize plotly express directly * Rmeocve old class * Use plotly express and modify stackgroup afterwards * Add modifications also to animations * Mkae more compact * Remove height stuff * Remove line and make set opacity =0 for area * Integrate faceting and animating into existing with_plotly method * Improve results.py * Improve results.py * Move check if dims are found to plotting.py * Fix usage of indexer * Change selection string with indexer * Change behaviout of parameter "indexing" * Update CHANGELOG.md * Add new selection parameter to plotting methods * deprectae old indexer parameter * deprectae old indexer parameter * Add test * Add test * Add test * Add test * Add heatmap support * Unify to a single heatmap method per engine * Change defaults * readd time reshaping * readd time reshaping * lengthen scenario example * Update * Improve heatmap plotting * Improve heatmap plotting * Moved reshaping to plotting.py * COmbinations are possible! * Improve 'auto'behavioour * Improve 'auto' behavioour * Improve 'auto' behavioour * Allow multiple variables in a heatmap * Update modeule level plot_heatmap() * remove code duplication * Allow Dataset instead of List of DataArrays * Allow Dataset instead of List of DataArrays * Add tests * More examples * Update plot_charge state() * Try 1 * Try 2 * Add more examples * Add more examples * Add smooth line for charge state and use "area" as default * Update scenario_example.py * Update tests * Handle extra dims in pie plots by selecting the first * 6. Optimized time-step check - Replaced pandas Series diff() with NumPy np.diff() for better performance - Changed check from > 0 to > 1 (can't calculate diff with 0 or 1 element) - Converted to seconds first, then to minutes to avoid pandas timedelta conversion issues * Typo * Improve type handling * Update other tests * Handle backwards compatability * Add better error messages if both new and old api are used * Add old api explicitly * Add old api explicitly * Improve consistency and properly deprectae the indexer parameter * Remove amount of new tests * Remove amount of new tests * Fix CONTRIBUTING.md * Remove old test file * Add tests/test_heatmap_reshape.py * Add tests/test_heatmap_reshape.py * Remove unused method * - Implemented dashed line styling for "mixed" variables (variables with both positive and negative values) - Only stack "positive" and "negative" classifications, not "mixed" or "zero" * - Added fill parameter to module-level plot_heatmap function (line 1914) - Added fill parameter to CalculationResults.plot_heatmap method (line 702) - Forwarded fill parameter to both heatmap_with_plotly and heatmap_with_matplotlib functions * - Added np.random.seed(42) for reproducible test results - Added specific size assertions to all tests: - Daily/hourly pattern: 3 days × 24 hours - Weekly/daily pattern: 1 week × 7 days - Irregular data: 25 hours × 60 minutes - Multidimensional: 2 days × 24 hours with preserved scenario dimension * Improve Error Message if too many dims for matplotlib * Improve Error Message if too many dims for matplotlib * Improve Error Message if too many dims for matplotlib * Rename _apply_indexer_to_data() to _apply_selection_to_data() * Bugfix * Update CHANGELOG.md * Catch edge case in with_plotly() * Add strict=True * Improve scenario_example.py * Improve scenario_example.py * Change logging level in essage about time reshape * Update CHANGELOG.md * Add XarrayColorMapper * Add XarrayColorMapper to CalculationResults * Renamed variable * Add test file * Improve integration of the ColorMapper * Improve integration of the ColorMapper * Update resolve_colors and move to plotting.py * Temporalily add example script to show/document intended usage * Add method create_color_mapper * Improve docstring * Remove example file again * Update CHANGELOG.md * Add create_color_mapper to SegmentedResults * Add create_color_mapper to complex_example * Missed some renames * Fix warning in plot_charge_state() * Allow for discrete color assignments with rules * Remove some half baked validation * Add more color families * Use 1:7 colors for more distinct colors * Add color mapper to complex example * Update CHANGELOG.md * Convert numpy style docstrings to google style * Use re.search instead of re.match * Update tests * Applying ordering to Dataset as well * This approach: - Prevents silent data loss when values like 1, 1.0, and "1" collide - Provides actionable error messages showing exactly which values are problematic - Allows users to fix their data rather than hiding the issue * Improve Error Message * Enable sorting fpr Datasets * completed the integration of XarrayColorMapper into both with_plotly and with_matplotlib * simplified with_matplotlib significantly * Update plotting methods to focus on xr.DataArray only * Remove duplication * Remove duplication * Make check faster * Make check faster * Make check faster * Fixx plotting issues * Switch back to Dataset first * Remove redundant code * XarrayColorMapper is now Dataset-only! * Update tests accordingly * Fix issue in aggregation.py with new plotting * Fix issue plotting in examples (using dataframes) * Fix issue plotting in examples (using dataframes) * Fix issue plotting scalar Datasets * Improve labeling of plots * Improve handling of time reshape in plots * Update usage of plotting methods * Update pie plots to use Dataset instead of DataFrame * Makde charge state line in plots black always * Improve examples * Make plotting methods much more flexible * Add test * Add plotting kwargs to plotting functions * add imshow kwargs * Fix nans in plots * Replace XarrayColorMapper with ComponentColorManager * Add repr and str method * Added tests * Add caching to ColorManager * Test caching * Change default colormap and improve colormap settings * Automatically initiallize the ColorManager * Use Dark24 as the default colormap * Rename auto_group_components() to apply_colors() * Use ColorManager in examples * Fix tests * Extend config to cover plotting settings * Centralize behaviour * More config options * More config options * More config options * Rename config parameter * Improve color defaults * Removed 'auto' and Simplified Color Resolution * Fix ColorProcessor to accept qualitative colorscales * Fix ColorProcessor to accept qualitative colorscales * Remove old test * Simplified tests * Update examples and CHANGELOG.md * Update method name * Update examples * extended ComponentColorManager to support flow-level color distinctio * Change default flow shading * Improve Setup_colors * Use external dependency for color handling * Make colour dependency optional * streamlined the ColorManager configuration API * streamlined the ColorManager configuration API * Update usages of new api * Update CHANGELOG.md * Update examples * use turbo as the new default sequential colormap * Add support for direct mappings of components * Add support for direct mappings of components * Add configurable flow_variation * Update tests * Make color getter mroe robust * Make color getter mroe robust * Temp * Update default colormap * Update default colormap to default colorscale * Update default Improve colorscale handling * Update default color families * Update plotly template * Update example * Simplify test * Update color family defaults * Simplify documentation * Typo * Make matplotlib backend switch more robst * Update setup_colors() in SegmentedCalculationResults * Fix example * Update CHANGELOG.md * Simplify export_figure() * Update Examples and CHANGELOG.md * Simplified Config * Simplified Colormanagement * Simplified Colormanagement * Simplified Colormanagement * Add element name itself to color dict * Fix examples * Bugfix * Bugfix * Remove coloring related stuff * Reverse color and CONFIG related changes in plotting.py * Reverse color and CONFIG related changes in plotting.py * Reverse color and CONFIG related changes in plotting.py * Reverse color and CONFIG related changes in plotting.py * Reverse color and CONFIG related changes in plotting.py * Update CHANGELOG.md * Update CHANGELOG.md * Remove duplicate resolve color calls * Improve pie plot * Simplify pie plot * Simplify pie plot * Bugfix * Bugfix * Bugfix * Bugfix * Bugfix * Add Series Support for plotting * Simplify pie plots to be Series First to remove unnessesary data transformations * Update Typehints * Test datatypes * Test datatypes and plotting modes * Test datatypes and plotting modes * Test datatypes and plotting modes * Test datatypes and plotting modes * Update CHANGELOG.md * Potential Bugfix * Fix: plotly kwargs usage * Update docstrings and fix usage of kwargs * Improve error handling * Remove trace and layout kwargs * Prevent potential bugs in plotting.py * Improve tests
1 parent 4305ed2 commit feb0ced

7 files changed

Lines changed: 899 additions & 564 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
5353
If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOpt/flixOpt/releases/tag/v3.0.0) and [Migration Guide](https://flixopt.github.io/flixopt/latest/user-guide/migration-guide-v3/).
5454
5555
### ✨ Added
56+
- Support for plotting kwargs in `results.py`, passed to plotly express and matplotlib.
5657
5758
### 💥 Breaking Changes
5859
5960
### ♻️ Changed
61+
- **Template integration**: Plotly templates now fully control plot styling without hardcoded overrides
62+
- **Dataset first plotting**: Underlying plotting methods in `plotting.py` now use `xr.Dataset` as the main datatype. DataFrames are automatically converted via `_ensure_dataset()`. Both DataFrames and Datasets can be passed to plotting functions without code changes.
6063
6164
### 🗑️ Deprecated
6265
6366
### 🔥 Removed
67+
- Removed `plotting.pie_with_plotly()` method as it was not used
6468
6569
### 🐛 Fixed
70+
- Improved error messages for `engine='matplotlib'` with multidimensional data
71+
- Better dimension validation in `results.plot_heatmap()`
6672
6773
### 🔒 Security
6874

examples/02_Complex/complex_example_results.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
# --- Detailed Plots ---
2626
# In depth plot for individual flow rates ('__' is used as the delimiter between Component and Flow
2727
results.plot_heatmap('Wärmelast(Q_th_Last)|flow_rate')
28-
for flow_rate in results['BHKW2'].inputs + results['BHKW2'].outputs:
29-
results.plot_heatmap(flow_rate)
28+
for bus in results.buses.values():
29+
bus.plot_node_balance_pie(show=False, save=f'results/{bus.label}--pie.html')
30+
bus.plot_node_balance(show=False, save=f'results/{bus.label}--balance.html')
3031

3132
# --- Plotting internal variables manually ---
3233
results.plot_heatmap('BHKW2(Q_th)|on')

examples/03_Calculation_types/example_calculation_types.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,35 +202,38 @@ def get_solutions(calcs: list, variable: str) -> xr.Dataset:
202202

203203
# --- Plotting for comparison ---
204204
fx.plotting.with_plotly(
205-
get_solutions(calculations, 'Speicher|charge_state').to_dataframe(),
205+
get_solutions(calculations, 'Speicher|charge_state'),
206206
mode='line',
207207
title='Charge State Comparison',
208208
ylabel='Charge state',
209+
xlabel='Time in h',
209210
).write_html('results/Charge State.html')
210211

211212
fx.plotting.with_plotly(
212-
get_solutions(calculations, 'BHKW2(Q_th)|flow_rate').to_dataframe(),
213+
get_solutions(calculations, 'BHKW2(Q_th)|flow_rate'),
213214
mode='line',
214215
title='BHKW2(Q_th) Flow Rate Comparison',
215216
ylabel='Flow rate',
217+
xlabel='Time in h',
216218
).write_html('results/BHKW2 Thermal Power.html')
217219

218220
fx.plotting.with_plotly(
219-
get_solutions(calculations, 'costs(temporal)|per_timestep').to_dataframe(),
221+
get_solutions(calculations, 'costs(temporal)|per_timestep'),
220222
mode='line',
221223
title='Operation Cost Comparison',
222224
ylabel='Costs [€]',
225+
xlabel='Time in h',
223226
).write_html('results/Operation Costs.html')
224227

225228
fx.plotting.with_plotly(
226-
pd.DataFrame(get_solutions(calculations, 'costs(temporal)|per_timestep').to_dataframe().sum()).T,
229+
get_solutions(calculations, 'costs(temporal)|per_timestep').sum('time'),
227230
mode='stacked_bar',
228231
title='Total Cost Comparison',
229232
ylabel='Costs [€]',
230233
).update_layout(barmode='group').write_html('results/Total Costs.html')
231234

232235
fx.plotting.with_plotly(
233-
pd.DataFrame([calc.durations for calc in calculations], index=[calc.name for calc in calculations]),
236+
pd.DataFrame([calc.durations for calc in calculations], index=[calc.name for calc in calculations]).to_xarray(),
234237
mode='stacked_bar',
235238
).update_layout(title='Duration Comparison', xaxis_title='Calculation type', yaxis_title='Time (s)').write_html(
236239
'results/Speed Comparison.html'

flixopt/aggregation.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,17 @@ def plot(self, colormap: str = 'viridis', show: bool = True, save: pathlib.Path
150150
df_agg = self.aggregated_data.copy().rename(
151151
columns={col: f'Aggregated - {col}' for col in self.aggregated_data.columns}
152152
)
153-
fig = plotting.with_plotly(df_org, 'line', colors=colormap)
153+
fig = plotting.with_plotly(df_org.to_xarray(), 'line', colors=colormap, xlabel='Time in h')
154154
for trace in fig.data:
155155
trace.update(dict(line=dict(dash='dash')))
156-
fig = plotting.with_plotly(df_agg, 'line', colors=colormap, fig=fig)
156+
fig2 = plotting.with_plotly(df_agg.to_xarray(), 'line', colors=colormap, xlabel='Time in h')
157+
for trace in fig2.data:
158+
fig.add_trace(trace)
157159

158160
fig.update_layout(
159-
title='Original vs Aggregated Data (original = ---)', xaxis_title='Index', yaxis_title='Value'
161+
title='Original vs Aggregated Data (original = ---)',
162+
xaxis_title='Time in h',
163+
yaxis_title='Value',
160164
)
161165

162166
plotting.export_figure(

0 commit comments

Comments
 (0)