如何制作图形matplotlib

eufgjt7s  于 2023-01-13  发布在  其他
关注(0)|答案(2)|浏览(180)

我在numpy有一个a帧:

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表示年

php[0] = 2015, 
php[1] = 2016, 
php[2] = 2017, 
php[3] = 2018, 
php[4] = 2019, 
php[5] = 2020, 
php[6] = 2021, 
php[7] = 2022
9avjhtql

9avjhtql1#

你可以这样做:

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()

结果是:

smdnsysy

smdnsysy2#

试试这个-

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()

相关问题