diff options
| author | Mitja Felicijan <m@mitjafelicijan.com> | 2023-08-01 17:08:37 +0200 |
|---|---|---|
| committer | Mitja Felicijan <m@mitjafelicijan.com> | 2023-08-01 17:08:37 +0200 |
| commit | 2efe4bc1a966da188da450782d8d74690933526b (patch) | |
| tree | dc43e7c598db27537053bc900e93eef68a8c3d25 /content | |
| parent | a64284a4ae72c4f4d6e5a6aa18337cbc5cc1247c (diff) | |
| download | mitjafelicijan.com-2efe4bc1a966da188da450782d8d74690933526b.tar.gz | |
Note: SVG charts with matplotlib
Diffstat (limited to 'content')
| -rw-r--r-- | content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md b/content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md new file mode 100644 index 0000000..50c3806 --- /dev/null +++ b/content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | --- | ||
| 2 | title: "Make B/W SVG charts with matplotlib" | ||
| 3 | url: make-b-w-svg-charts-with-matplotlib.html | ||
| 4 | date: 2023-08-01T17:04:10+02:00 | ||
| 5 | type: note | ||
| 6 | draft: false | ||
| 7 | --- | ||
| 8 | |||
| 9 | Install pip requirements. | ||
| 10 | |||
| 11 | ```sh | ||
| 12 | pip install matplotlib | ||
| 13 | pip install numpy | ||
| 14 | pip install pandas | ||
| 15 | ``` | ||
| 16 | |||
| 17 | Now execute the script. | ||
| 18 | |||
| 19 | ```python | ||
| 20 | import csv | ||
| 21 | import sys | ||
| 22 | |||
| 23 | import matplotlib.pyplot as plt | ||
| 24 | import numpy as np | ||
| 25 | import pandas as pd | ||
| 26 | |||
| 27 | # Read the data | ||
| 28 | df = pd.read_csv("data.csv") | ||
| 29 | |||
| 30 | # Settings | ||
| 31 | plt.title("Connect median NLB vs ALB") | ||
| 32 | fig = plt.gcf() | ||
| 33 | fig.set_size_inches(10, 4) | ||
| 34 | |||
| 35 | # Plotting | ||
| 36 | plt.plot(df["Epoch"], df["Connect (ALB)"], label = "ALB", color="black", linestyle="-") | ||
| 37 | plt.plot(df["Epoch"], df["Connect (NLB)"], label = "NLB", color="black", linestyle="--") | ||
| 38 | |||
| 39 | # Adding x and y axis labels | ||
| 40 | plt.xlabel("Epoch", fontstyle="italic") | ||
| 41 | plt.ylabel("Median value (ms)", fontstyle="italic") | ||
| 42 | |||
| 43 | # Legend | ||
| 44 | legend = plt.legend() | ||
| 45 | legend.get_frame().set_linewidth(0) | ||
| 46 | |||
| 47 | # Export as SVG | ||
| 48 | plt.savefig("plot.svg", format="svg") | ||
| 49 | ``` | ||
| 50 | |||
| 51 |  | ||
