How to make graph matplotlib

Question:

I have got an a frames in numpy:

php = np.array([282, 804, 1209, 1558, 1368, 1208, 594, 224])
js = np.array([273, 902, 1355, 1647, 1501, 1424, 678, 186])
html = np.array([229, 626, 865, 1275, 1134, 959, 446, 138])
html5 = np.array([227, 596, 764, 879, 715, 610, 264, 67])
my_sql = np.array([218, 620, 996, 1150, 1008, 1001, 450, 156])
css = np.array([217, 568, 915, 1207, 1092, 981, 479, 132 ])
css3 = np.array([203, 535, 548, 704, 567, 487, 218, 0])
php5 = np.array([184, 392, 0, 0, 0, 0, 0, 0 ])
jquery = np.array([168, 604, 901, 1014, 808, 750, 349, 73 ])
c1_bitrix = np.array([168, 0, 454, 539, 513, 0, 225, 65 ])
git = np.array([0, 376, 663, 834, 734, 870, 408, 130 ])
oop = np.array([0, 0, 0, 0, 0, 481, 0, 84 ])

How can i make graph like this?

enter image description here

The X is years, for example

php[0] = 2015, 
php[1] = 2016, 
php[2] = 2017, 
php[3] = 2018, 
php[4] = 2019, 
php[5] = 2020, 
php[6] = 2021, 
php[7] = 2022
Asked By: Proger228

||

Answers:

You could do something like this:

import numpy as np
import matplotlib.pyplot as plt

php = np.array([282, 804, 1209, 1558, 1368, 1208, 594, 224])
js = np.array([273, 902, 1355, 1647, 1501, 1424, 678, 186])
html = np.array([229, 626, 865, 1275, 1134, 959, 446, 138])
html5 = np.array([227, 596, 764, 879, 715, 610, 264, 67])
my_sql = np.array([218, 620, 996, 1150, 1008, 1001, 450, 156])
css = np.array([217, 568, 915, 1207, 1092, 981, 479, 132 ])
css3 = np.array([203, 535, 548, 704, 567, 487, 218, 0])
php5 = np.array([184, 392, 0, 0, 0, 0, 0, 0 ])
jquery = np.array([168, 604, 901, 1014, 808, 750, 349, 73 ])
c1_bitrix = np.array([168, 0, 454, 539, 513, 0, 225, 65 ])
git = np.array([0, 376, 663, 834, 734, 870, 408, 130 ])
oop = np.array([0, 0, 0, 0, 0, 481, 0, 84 ])

x = np.arange(2015, 2023)
data = [php, js, html, html5, my_sql, css, css3, php5, jquery, c1_bitrix, git, oop]
labels = ['php', 'js', 'html', 'html5', 'my_sql', 'css', 'css3', 'php5', 'jquery', 'c1_bitrix', 'git', 'oop']


plt.figure(figsize = (6,10))
for y in data:
    plt.plot(x, y)    
plt.legend(labels = labels, loc = "upper left")
plt.show()

The result:

enter image description here

Answered By: Ben Grossmann

Try this –

import matplotlib.pyplot as plt

php = np.array([282, 804, 1209, 1558, 1368, 1208, 594, 224])
js = np.array([273, 902, 1355, 1647, 1501, 1424, 678, 186])
html = np.array([229, 626, 865, 1275, 1134, 959, 446, 138])
html5 = np.array([227, 596, 764, 879, 715, 610, 264, 67])
my_sql = np.array([218, 620, 996, 1150, 1008, 1001, 450, 156])
css = np.array([217, 568, 915, 1207, 1092, 981, 479, 132 ])
css3 = np.array([203, 535, 548, 704, 567, 487, 218, 0])
php5 = np.array([184, 392, 0, 0, 0, 0, 0, 0 ])
jquery = np.array([168, 604, 901, 1014, 808, 750, 349, 73 ])
c1_bitrix = np.array([168, 0, 454, 539, 513, 0, 225, 65 ])
git = np.array([0, 376, 663, 834, 734, 870, 408, 130 ])
oop = np.array([0, 0, 0, 0, 0, 481, 0, 84 ])

legends = ['php', 'js', 'html', 'html5', 'my_sql', 'css', 'php5', 'jquery', 'c1_bitrix', 'git', 'oop']
years = [str(i) for i in range(2015,2023)]

fig = plt.figure(figsize=(7,10))

for i in legends:
    plt.plot(eval(i))

plt.legend(legends, loc='upper left')
plt.xticks(range(len(years)), years, size='small')
plt.show()

enter image description here

Answered By: Akshay Sehgal
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.