Skip to content

Commit 8b3afad

Browse files
committed
Refactor plot.py to include date formatting and tick locator
1 parent 2aff7a8 commit 8b3afad

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

anomstack/plots/plot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pandas as pd
77
import seaborn as sns
88
from matplotlib.figure import Figure
9+
import matplotlib.dates as mdates
10+
from matplotlib.ticker import MaxNLocator
911

1012

1113
def make_alert_plot(
@@ -101,6 +103,7 @@ def make_batch_plot(df: pd.DataFrame) -> plt.Figure:
101103
Returns:
102104
plt.Figure: The generated batch plot figure.
103105
"""
106+
df['metric_timestamp'] = pd.to_datetime(df['metric_timestamp'])
104107
unique_metrics = df["metric_name"].unique()
105108
colors = sns.color_palette("viridis", len(unique_metrics))
106109

@@ -123,11 +126,14 @@ def make_batch_plot(df: pd.DataFrame) -> plt.Figure:
123126
label="Metric Value",
124127
color=colors[i],
125128
ax=ax1,
126-
legend=True,
129+
legend=False,
127130
)
128131
ax1.set_ylabel("Metric Value")
129132
ax1.tick_params(axis="y", labelcolor=colors[i])
130133

134+
ax1.xaxis.set_major_locator(MaxNLocator(nbins=5))
135+
ax1.xaxis.set_major_formatter(mdates.DateFormatter("%Y-%m-%d %H:%M"))
136+
131137
ax2 = ax1.twinx()
132138
sns.lineplot(
133139
data=metric_data,

0 commit comments

Comments
 (0)