How can I plot a simple chart where the x-axis is AGE and the Y-axis(values) are HEIGHT and WEIGHT from a file called ‘data-file-2022’?
file only has these 3 columns all integers , ‘age’ age of the person, ‘height’ height in nearest CMs and ‘weight’ weight in nearest KGs
I want to have x-axis as age, while plotting the height and weight as CHART.
>Solution :
You could use the matplotlib library, I assume you either want a line or a scatter chart.
Line chart:
Code:
import matplotlib.pyplot as mpl
age = [34,17,45,19]
height = [184,172,168,188]
weight = [83,78,65,88]
age, height, weight = zip(*sorted(zip(age, height, weight)))
mpl.plot(age,height)
mpl.plot(age,weight)
mpl.show()
Output
Scatter chart:
Code:
import matplotlib.pyplot as mpl
age = [34,17,45,19]
height = [184,172,168,188]
weight = [83,78,65,88]
mpl.scatter(age,height)
mpl.scatter(age,weight)
mpl.show()
Output
You have to convert your file into lists but without knowing more about your file I can’t help you further.