Skip to content

Commit

Permalink
Use plot() instead of deprecated plot_date()
Browse files Browse the repository at this point in the history
plot_date() has been discouraged since matplotlib 3.5, and deprecated from 3.9. Instead
we use plot() directly, and the datatype of the first argument (the x-data) will
determine the kind of plot.
  • Loading branch information
berland committed Sep 4, 2024
1 parent 0303a8a commit cb5ea32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
33 changes: 10 additions & 23 deletions src/ert/gui/plottery/plots/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def plot(
config,
data,
f"{ensemble.experiment_name} : {ensemble.name}",
plot_context.isDateSupportActive(),
)
config.nextColor()

Expand All @@ -72,34 +71,22 @@ def _plotLines(
plot_config: PlotConfig,
data: pd.DataFrame,
ensemble_label: str,
is_date_supported: bool,
) -> None:
style = plot_config.defaultStyle()

if len(data) == 1 and not style.marker:
style.marker = "."

if is_date_supported:
lines = axes.plot_date(
x=data.index.to_numpy(),
y=data.to_numpy(),
color=style.color,
alpha=style.alpha,
linewidth=style.width,
markersize=style.size,
fmt=f"{style.marker}{style.line_style}",
)
else:
lines = axes.plot(
data.index.to_numpy(),
data.to_numpy(),
color=style.color,
alpha=style.alpha,
marker=style.marker,
linestyle=style.line_style,
linewidth=style.width,
markersize=style.size,
)
lines = axes.plot(
data.index.to_numpy(),
data.to_numpy(),
color=style.color,
alpha=style.alpha,
marker=style.marker,
linewidth=style.width,
linestyle=style.line_style,
markersize=style.size,
)

if len(lines) > 0:
plot_config.addLegendItem(ensemble_label, lines[0])
11 changes: 5 additions & 6 deletions src/ert/gui/plottery/plots/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ def plotHistory(plot_context: "PlotContext", axes: "Axes") -> None:
):
return

data = plot_context.history_data

style = plot_config.historyStyle()

lines = axes.plot_date(
x=data.index.values,
y=data,
lines = axes.plot(
plot_context.history_data.index.values,
plot_context.history_data,
color=style.color,
alpha=style.alpha,
linewidth=style.width,
markersize=style.size,
fmt=f"{style.marker}{style.line_style}",
marker=style.marker,
linestyle=style.line_style,
)

if len(lines) > 0 and style.isVisible():
Expand Down

0 comments on commit cb5ea32

Please sign in to comment.