作者:非妃是公主
专栏:《python学习》
个性签:顺境不惰,逆境不馁,以心制境,万事可成。——曾国藩
更具表格中的数据,画出相应的折线图:
时间 | 国民总收入(亿元) |
---|---|
1952 | 679.1 |
1953 | 824.4 |
1954 | 859.8 |
1955 | 911.6 |
1956 | 1030.7 |
1957 | 1071.4 |
1958 | 1312.3 |
1959 | 1447.5 |
1960 | 1470.1 |
最终结果:
代码如下:
import matplotlib.pyplot as plt # python中画图所用到的第三方库
y = [1470.1, 1447.5, 1312.3, 1071.4, 1030.7, 911.6, 859.8, 824.4, 679.1] # 1956-1920年对应的GDP值,单位亿元
x = [1960, 1959, 1958, 1957, 1956, 1955, 1954, 1953, 1952] # 1952-1960年
plt.scatter(x, y) # 画点,将列表中的值分别画在plot中
plt.plot(x, y, color='r') # 连线,按顺序将
plt.xlabel("year") # 横轴的标签
plt.ylabel("GDP/Billion") # 纵轴的标签
plt.title("Changes in China's GDP since the founding of the PRC") # 图像标头
plt.show() # 相当于将图像显示出,必须要加上才能显示出图像