diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-01 22:54:27 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-01 22:54:27 +0100 |
| commit | 2417a6b7603524dc5cd30d29b153f91024b9443d (patch) | |
| tree | 9be5ea8e5baba96dd9159217da6badf6157fb595 /content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md | |
| parent | 89ba3497f07a8ea43d209b583f39fcc286acc923 (diff) | |
| download | mitjafelicijan.com-2417a6b7603524dc5cd30d29b153f91024b9443d.tar.gz | |
Move to Jekyll
Diffstat (limited to 'content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md')
| -rw-r--r-- | content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md | 70 |
1 files changed, 0 insertions, 70 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 deleted file mode 100644 index 51e85ec..0000000 --- a/content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md +++ /dev/null | |||
| @@ -1,70 +0,0 @@ | |||
| 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 pandas | ||
| 14 | ``` | ||
| 15 | |||
| 16 | Example of data being used. | ||
| 17 | |||
| 18 | ```text | ||
| 19 | Epoch,Connect (NLB),Processing (NLB),Waiting (NLB),Total (NLB),Connect (ALB),Processing (ALB),Waiting (ALB),Total (ALB) | ||
| 20 | 1,57.7,315.7,309.4,321.6,9,104.4,98.3,105.7 | ||
| 21 | 2,121.9,114.4,100.3,176.9,5.8,99.1,97.1,101.1 | ||
| 22 | 3,5.3,229.4,231.2,231.4,14.2,83,69.4,87.9 | ||
| 23 | 4,4.2,134.5,112.2,135.3,5.3,132.4,105.5,134.1 | ||
| 24 | 5,5.8,247.4,246.8,248.1,6,74.3,70.2,75.5 | ||
| 25 | 6,9.9,122.9,100.6,122.7,7.5,241.1,79.3,242.3 | ||
| 26 | 7,6.1,170.2,106.4,170.5,7.2,382.4,375.1,383.8 | ||
| 27 | 8,6.6,194.3,201.4,195.5,7.1,130.9,104.8,132.6 | ||
| 28 | 9,6.4,146.1,122.3,147.7,9.4,95.6,74,96.4 | ||
| 29 | ``` | ||
| 30 | |||
| 31 | In the code you can use `df` as dataframes and use the headers like `df["Epoch"]`. | ||
| 32 | This is how you get a column data with pandas. | ||
| 33 | |||
| 34 | The Python code responsible for generating a chart: | ||
| 35 | |||
| 36 | ```python | ||
| 37 | import csv | ||
| 38 | import sys | ||
| 39 | |||
| 40 | import matplotlib.pyplot as plt | ||
| 41 | import pandas as pd | ||
| 42 | |||
| 43 | # Read the data | ||
| 44 | df = pd.read_csv("data.csv") | ||
| 45 | |||
| 46 | # Settings | ||
| 47 | plt.title("Connect median NLB vs ALB") | ||
| 48 | plt.tight_layout(pad=2) | ||
| 49 | fig = plt.gcf() | ||
| 50 | fig.set_size_inches(10, 4) | ||
| 51 | |||
| 52 | # Plotting | ||
| 53 | plt.plot(df["Epoch"], df["Connect (ALB)"], label = "ALB", color="black", linestyle="-") | ||
| 54 | plt.plot(df["Epoch"], df["Connect (NLB)"], label = "NLB", color="black", linestyle="--") | ||
| 55 | |||
| 56 | # Adding x and y axis labels | ||
| 57 | plt.xlabel("Epoch", fontstyle="italic") | ||
| 58 | plt.ylabel("Median value (ms)", fontstyle="italic") | ||
| 59 | |||
| 60 | # Legend | ||
| 61 | legend = plt.legend() | ||
| 62 | legend.get_frame().set_linewidth(0) | ||
| 63 | |||
| 64 | # Export as SVG | ||
| 65 | plt.savefig("plot.svg", format="svg") | ||
| 66 | ``` | ||
| 67 | |||
| 68 |  | ||
| 69 | |||
| 70 | The image above is SVG and you can zoom in and out and check that the image is vector. | ||
