diff options
| -rw-r--r-- | content/notes/2023-08-01-make-b-w-svg-charts-with-matplotlib.md | 24 |
1 files changed, 21 insertions, 3 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 index 50c3806..c3fef57 100644 --- 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 | |||
| @@ -10,18 +10,34 @@ Install pip requirements. | |||
| 10 | 10 | ||
| 11 | ```sh | 11 | ```sh |
| 12 | pip install matplotlib | 12 | pip install matplotlib |
| 13 | pip install numpy | ||
| 14 | pip install pandas | 13 | pip install pandas |
| 15 | ``` | 14 | ``` |
| 16 | 15 | ||
| 17 | Now execute the script. | 16 | Example of data being used. |
| 17 | |||
| 18 | ```csv | ||
| 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: | ||
| 18 | 35 | ||
| 19 | ```python | 36 | ```python |
| 20 | import csv | 37 | import csv |
| 21 | import sys | 38 | import sys |
| 22 | 39 | ||
| 23 | import matplotlib.pyplot as plt | 40 | import matplotlib.pyplot as plt |
| 24 | import numpy as np | ||
| 25 | import pandas as pd | 41 | import pandas as pd |
| 26 | 42 | ||
| 27 | # Read the data | 43 | # Read the data |
| @@ -49,3 +65,5 @@ plt.savefig("plot.svg", format="svg") | |||
| 49 | ``` | 65 | ``` |
| 50 | 66 | ||
| 51 |  | 67 |  |
| 68 | |||
| 69 | The image above is SVG and you can zoom in and out and check that the image is vector. | ||
