Skip to content

Commit 0cd2d55

Browse files
committed
Formatting
1 parent 2678175 commit 0cd2d55

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

petab/parameter_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def merge_preeq_and_sim_pars_condition(
593593
This function is meant for the case where we cannot have different
594594
parameters (and scales) for preequilibration and simulation. Therefore,
595595
merge both and ensure matching scales and parameters.
596-
``condition_map_sim`` and ``condition_scale_map_sim`` will ne modified in
596+
``condition_map_sim`` and ``condition_scale_map_sim`` will be modified in
597597
place.
598598
599599
Arguments:

petab/visualize/plotter.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ def __init__(self, figure: Figure, data_provider: DataProvider):
3333
self.data_provider = data_provider
3434

3535
@abstractmethod
36-
def generate_figure(self, subplot_dir: Optional[str] = None
37-
) -> Optional[Dict[str, plt.Subplot]]:
36+
def generate_figure(
37+
self,
38+
subplot_dir: Optional[str] = None
39+
) -> Optional[Dict[str, plt.Subplot]]:
3840
pass
3941

4042

@@ -65,9 +67,12 @@ def _error_column_for_plot_type_data(plot_type_data: str) -> Optional[str]:
6567
return 'noise_model'
6668
return None
6769

68-
def generate_lineplot(self, ax: 'matplotlib.pyplot.Axes',
69-
dataplot: DataPlot,
70-
plotTypeData: str) -> None:
70+
def generate_lineplot(
71+
self,
72+
ax: 'matplotlib.pyplot.Axes',
73+
dataplot: DataPlot,
74+
plotTypeData: str
75+
) -> None:
7176
"""
7277
Generate lineplot.
7378
@@ -82,7 +87,6 @@ def generate_lineplot(self, ax: 'matplotlib.pyplot.Axes',
8287
plotTypeData:
8388
Specifies how replicates should be handled.
8489
"""
85-
8690
simu_color = None
8791
measurements_to_plot, simulations_to_plot = \
8892
self.data_provider.get_data_to_plot(dataplot,
@@ -152,9 +156,12 @@ def generate_lineplot(self, ax: 'matplotlib.pyplot.Axes',
152156
label=label_base + " simulation", color=simu_color
153157
)
154158

155-
def generate_barplot(self, ax: 'matplotlib.pyplot.Axes',
156-
dataplot: DataPlot,
157-
plotTypeData: str) -> None:
159+
def generate_barplot(
160+
self,
161+
ax: 'matplotlib.pyplot.Axes',
162+
dataplot: DataPlot,
163+
plotTypeData: str
164+
) -> None:
158165
"""
159166
Generate barplot.
160167
@@ -200,9 +207,12 @@ def generate_barplot(self, ax: 'matplotlib.pyplot.Axes',
200207
color='white', edgecolor=color, **bar_kwargs,
201208
label='simulation')
202209

203-
def generate_scatterplot(self, ax: 'matplotlib.pyplot.Axes',
204-
dataplot: DataPlot,
205-
plotTypeData: str) -> None:
210+
def generate_scatterplot(
211+
self,
212+
ax: 'matplotlib.pyplot.Axes',
213+
dataplot: DataPlot,
214+
plotTypeData: str
215+
) -> None:
206216
"""
207217
Generate scatterplot.
208218
@@ -215,7 +225,6 @@ def generate_scatterplot(self, ax: 'matplotlib.pyplot.Axes',
215225
plotTypeData:
216226
Specifies how replicates should be handled.
217227
"""
218-
219228
measurements_to_plot, simulations_to_plot = \
220229
self.data_provider.get_data_to_plot(dataplot,
221230
plotTypeData == PROVIDED)
@@ -228,9 +237,11 @@ def generate_scatterplot(self, ax: 'matplotlib.pyplot.Axes',
228237
label=getattr(dataplot, LEGEND_ENTRY))
229238
self._square_plot_equal_ranges(ax)
230239

231-
def generate_subplot(self,
232-
ax,
233-
subplot: Subplot) -> None:
240+
def generate_subplot(
241+
self,
242+
ax: plt.Axes,
243+
subplot: Subplot
244+
) -> None:
234245
"""
235246
Generate subplot based on markup provided by subplot.
236247
@@ -241,7 +252,6 @@ def generate_subplot(self,
241252
subplot:
242253
Subplot visualization settings.
243254
"""
244-
245255
# set yScale
246256
if subplot.yScale == LIN:
247257
ax.set_yscale("linear")
@@ -270,7 +280,6 @@ def generate_subplot(self,
270280
for data_plot in subplot.data_plots:
271281
self.generate_scatterplot(ax, data_plot, subplot.plotTypeData)
272282
else:
273-
274283
# set xScale
275284
if subplot.xScale == LIN:
276285
ax.set_xscale("linear")
@@ -345,7 +354,6 @@ def generate_figure(
345354
None:
346355
In case subplots are saved to file.
347356
"""
348-
349357
if subplot_dir is None:
350358
# compute, how many rows and columns we need for the subplots
351359
num_row = int(np.round(np.sqrt(self.figure.num_subplots)))
@@ -361,7 +369,7 @@ def generate_figure(
361369
axes = dict(zip([plot.plotId for plot in self.figure.subplots],
362370
axes.flat))
363371

364-
for idx, subplot in enumerate(self.figure.subplots):
372+
for subplot in self.figure.subplots:
365373
if subplot_dir is not None:
366374
fig, ax = plt.subplots(figsize=self.figure.size)
367375
fig.set_tight_layout(True)
@@ -419,6 +427,8 @@ class SeabornPlotter(Plotter):
419427
def __init__(self, figure: Figure, data_provider: DataProvider):
420428
super().__init__(figure, data_provider)
421429

422-
def generate_figure(self, subplot_dir: Optional[str] = None
423-
) -> Optional[Dict[str, plt.Subplot]]:
430+
def generate_figure(
431+
self,
432+
subplot_dir: Optional[str] = None
433+
) -> Optional[Dict[str, plt.Subplot]]:
424434
pass

petab/visualize/plotting.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33
from numbers import Number, Real
44
from pathlib import Path
5-
from typing import Dict, List, Optional, Tuple, Union
5+
from typing import Dict, List, Optional, Tuple, Union, Literal
66

77
import numpy as np
88
import pandas as pd
@@ -130,6 +130,9 @@ def from_df(cls, plot_spec: pd.DataFrame):
130130

131131
return cls(vis_spec_dict)
132132

133+
def __repr__(self):
134+
return f"{self.__class__.__name__}({self.__dict__})"
135+
133136

134137
class Subplot:
135138
"""
@@ -480,9 +483,13 @@ def _get_independent_var_values(self, data_df: pd.DataFrame,
480483

481484
return uni_condition_id, col_name_unique, conditions_
482485

483-
def get_data_series(self, data_df: pd.DataFrame, data_col: str,
484-
dataplot: DataPlot,
485-
provided_noise: bool) -> DataSeries:
486+
def get_data_series(
487+
self,
488+
data_df: pd.DataFrame,
489+
data_col: Literal['measurement', 'simulation'],
490+
dataplot: DataPlot,
491+
provided_noise: bool
492+
) -> DataSeries:
486493
"""
487494
Get data to plot from measurement or simulation DataFrame.
488495
@@ -499,10 +506,8 @@ def get_data_series(self, data_df: pd.DataFrame, data_col: str,
499506
-------
500507
Data to plot
501508
"""
502-
503509
uni_condition_id, col_name_unique, conditions_ = \
504-
self._get_independent_var_values(data_df,
505-
dataplot)
510+
self._get_independent_var_values(data_df, dataplot)
506511

507512
dataset_id = getattr(dataplot, DATASET_ID)
508513

@@ -643,8 +648,10 @@ def _data_df(self):
643648
None else self.simulations_data
644649

645650
@staticmethod
646-
def create_subplot(plot_id: str,
647-
subplot_vis_spec: pd.DataFrame) -> Subplot:
651+
def create_subplot(
652+
plot_id: str,
653+
subplot_vis_spec: pd.DataFrame
654+
) -> Subplot:
648655
"""
649656
Create subplot.
650657
@@ -661,7 +668,6 @@ def create_subplot(plot_id: str,
661668
662669
Subplot
663670
"""
664-
665671
subplot_columns = [col for col in subplot_vis_spec.columns if col in
666672
VISUALIZATION_DF_SUBPLOT_LEVEL_COLS]
667673
subplot = Subplot.from_df(plot_id,
@@ -677,9 +683,10 @@ def create_subplot(plot_id: str,
677683

678684
return subplot
679685

680-
def parse_from_vis_spec(self,
681-
vis_spec: Optional[Union[str, Path, pd.DataFrame]],
682-
) -> Tuple[Figure, DataProvider]:
686+
def parse_from_vis_spec(
687+
self,
688+
vis_spec: Optional[Union[str, Path, pd.DataFrame]],
689+
) -> Tuple[Figure, DataProvider]:
683690
"""
684691
Get visualization settings from a visualization specification.
685692
@@ -694,7 +701,6 @@ def parse_from_vis_spec(self,
694701
695702
A figure template with visualization settings and a data provider
696703
"""
697-
698704
# import visualization specification, if file was specified
699705
if isinstance(vis_spec, (str, Path)):
700706
vis_spec = core.get_visualization_df(vis_spec)

0 commit comments

Comments
 (0)