Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plotting a simple chart on Python Or R with X-Value(AGE), and Y-VALUES(HEIGHT and WEIGHT)

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading