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