aboutsummaryrefslogtreecommitdiff
path: root/_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-02-23 10:35:22 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-02-23 10:35:22 +0100
commit4abcce013c9ee3053badf2abda77190233066676 (patch)
tree450de7e8fed3c3c7501a9d2e2eb60a676bdfa09e /_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md
parentcdf50cb2e3051200c6ea0628c318d66220b7d1a1 (diff)
downloadmitjafelicijan.com-4abcce013c9ee3053badf2abda77190233066676.tar.gz
Testing thoughts page
Diffstat (limited to '_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md')
-rw-r--r--_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md71
1 files changed, 0 insertions, 71 deletions
diff --git a/_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md b/_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md
deleted file mode 100644
index 461842d..0000000
--- a/_posts/2023-08-01-make-b-w-svg-charts-with-matplotlib.md
+++ /dev/null
@@ -1,71 +0,0 @@
1---
2title: "Make B/W SVG charts with matplotlib"
3permalink: /make-b-w-svg-charts-with-matplotlib.html
4date: 2023-08-01T17:04:10+02:00
5layout: post
6type: note
7draft: false
8---
9
10Install pip requirements.
11
12```sh
13pip install matplotlib
14pip install pandas
15```
16
17Example of data being used.
18
19```text
20Epoch,Connect (NLB),Processing (NLB),Waiting (NLB),Total (NLB),Connect (ALB),Processing (ALB),Waiting (ALB),Total (ALB)
211,57.7,315.7,309.4,321.6,9,104.4,98.3,105.7
222,121.9,114.4,100.3,176.9,5.8,99.1,97.1,101.1
233,5.3,229.4,231.2,231.4,14.2,83,69.4,87.9
244,4.2,134.5,112.2,135.3,5.3,132.4,105.5,134.1
255,5.8,247.4,246.8,248.1,6,74.3,70.2,75.5
266,9.9,122.9,100.6,122.7,7.5,241.1,79.3,242.3
277,6.1,170.2,106.4,170.5,7.2,382.4,375.1,383.8
288,6.6,194.3,201.4,195.5,7.1,130.9,104.8,132.6
299,6.4,146.1,122.3,147.7,9.4,95.6,74,96.4
30```
31
32In the code you can use `df` as dataframes and use the headers like `df["Epoch"]`.
33This is how you get a column data with pandas.
34
35The Python code responsible for generating a chart:
36
37```python
38import csv
39import sys
40
41import matplotlib.pyplot as plt
42import pandas as pd
43
44# Read the data
45df = pd.read_csv("data.csv")
46
47# Settings
48plt.title("Connect median NLB vs ALB")
49plt.tight_layout(pad=2)
50fig = plt.gcf()
51fig.set_size_inches(10, 4)
52
53# Plotting
54plt.plot(df["Epoch"], df["Connect (ALB)"], label = "ALB", color="black", linestyle="-")
55plt.plot(df["Epoch"], df["Connect (NLB)"], label = "NLB", color="black", linestyle="--")
56
57# Adding x and y axis labels
58plt.xlabel("Epoch", fontstyle="italic")
59plt.ylabel("Median value (ms)", fontstyle="italic")
60
61# Legend
62legend = plt.legend()
63legend.get_frame().set_linewidth(0)
64
65# Export as SVG
66plt.savefig("plot.svg", format="svg")
67```
68
69![SVG Chart](/assets/notes/plot.svg){:loading="lazy"}
70
71The image above is SVG and you can zoom in and out and check that the image is vector.