Skip to content

Commit 6a226c5

Browse files
authored
Merge pull request #103 from andrewm4894/small-plotting-improvements
Small plotting improvements
2 parents 9cd30b8 + 9f43a78 commit 6a226c5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

anomstack/jobs/plot.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
from anomstack.plots.plot import make_batch_plot
2525
from anomstack.sql.read import read_sql
2626

27-
ANOMSTACK_MAX_RUNTIME_SECONDS_TAG = os.getenv("ANOMSTACK_MAX_RUNTIME_SECONDS_TAG", 3600)
27+
ANOMSTACK_MAX_RUNTIME_SECONDS_TAG = os.getenv(
28+
"ANOMSTACK_MAX_RUNTIME_SECONDS_TAG", 3600
29+
)
2830

2931

3032
def build_plot_job(spec: dict) -> JobDefinition:
@@ -37,7 +39,6 @@ def build_plot_job(spec: dict) -> JobDefinition:
3739
JobDefinition: The plot job definition.
3840
"""
3941

40-
4142
if spec.get("disable_plot"):
4243

4344
@job(

anomstack/plots/plot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Some helper functions for plotting.
33
"""
44

5+
import matplotlib.dates as mdates
56
import matplotlib.pyplot as plt
67
import pandas as pd
78
import seaborn as sns
89
from matplotlib.figure import Figure
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)