Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Charts #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions report/charts/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from collections import defaultdict
from typing import Dict, List
from typing import Any, Dict, List

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.axes import Axes

from report.charts.chart_argument_parser import ChartArgumentParser
from report.log_parser import LogParser
Expand All @@ -17,6 +17,16 @@ def select_metric(all_data: Dict[str, List[Dict[str, float]]], metric: str) -> D
return data


def configure_x_axis(axes: Axes, json_data: Dict[str, Any]) -> Axes:
axes.set_xticks(ticks=range(len(json_data['xticks'])))
axes.set_xticklabels(json_data['xticks'])

xlabel = json_data.get('xlabel')
if xlabel is not None:
axes.set_xlabel(xlabel=xlabel)
return axes


def main() -> None:
args = ChartArgumentParser(underscores_to_dashes=True).parse_args()
with args.config.open() as file:
Expand All @@ -40,14 +50,19 @@ def main() -> None:
config_name = json_data['name']
chart_name = args.save_path / f'{config_name}_{metric}.png'
prepared_data = select_metric(data, metric)

figure = plt.figure(figsize=(4,4), dpi=800)
axes = figure.gca()

for line_name, values in prepared_data.items():
axes.plot(values, label=line_name)

axes.legend()
axes.set_xticks(ticks=np.linspace(0, 3, 4))
axes.set_xticklabels(['0', '0.1', '0.15', '0.2'])

axes = configure_x_axis(axes, json_data)

axes.set_title(process_metric_name(metric))

figure.tight_layout()
figure.savefig(chart_name)
plt.close(figure)
Expand Down
4 changes: 3 additions & 1 deletion report/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Below is an example of a configuration file (config.json) to customize the behav
"ari",
"ami",
"time",
]
],
"xticks": ["2", "4", "8", "16", "15"],
"xlabel": "[Optional] Name of X Axis"
}
```

Expand Down