Skip to content
Snippets Groups Projects
Verified Commit adf97c54 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

add style support for bars

parent cf533bfd
Branches
No related tags found
No related merge requests found
......@@ -131,6 +131,7 @@ if __name__ == "__main__":
)
multi_bar_parser.add_argument("data", type=str, nargs="?", help=f"the actual data to show in a multibar plot\n\n{multi_bar.HELP}")
multi_bar_parser.add_argument("--label", "-l", type=str, help="the measurement label of the multibar plot")
multi_bar_parser.add_argument("--style", type=str, default="{}", help="specification for the style of the bar plots, in JSON")
common_options = [
{
......@@ -213,6 +214,7 @@ if __name__ == "__main__":
args.label,
plot_layout=plot_layout,
use_tex=args.use_tex,
style=json.loads(args.style),
)
if fig is None:
......
......@@ -28,6 +28,20 @@ HELP = """# Example
"charlie": 68.7
}
}
```
and the style could be something like
```json
{
"alice": {
"color": [ 0.6823529411764706, 0.7764705882352941, 0.8117647058823529 ]
},
"bob": {
"color": [ 1, 0.4117647058823529, 0.3803921568627451 ]
},
"charlie": {
"color": [ 0.4666666666666667, 0.8666666666666667, 0.4666666666666667 ]
}
}
```"""
......@@ -69,6 +83,7 @@ def multi_bar(
legend_loc: str = "upper left",
plot_layout: str = "constrained",
use_tex: bool = False,
style: dict = {},
) -> matplotlib.figure.Figure:
if labels_locations is None:
labels_locations = np.arange(len(groups))
......@@ -85,7 +100,7 @@ def multi_bar(
fig, ax = plt.subplots(layout=plot_layout)
for i, (attribute, measurement) in enumerate(measurements.items()):
rects = ax.bar(labels_locations + width * i, measurement, width, label=attribute)
rects = ax.bar(labels_locations + width * i, measurement, width, label=attribute, **style.get(attribute, {}))
ax.bar_label(rects, padding=3)
ax.set_ylabel(y_label)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment