matplotlib绘图显示不完全

就是这样,不能画出折线图,求指教!!

img

import pandas as pd
import matplotlib.pyplot as plt   #导入绘图库
plt.figure()   #创建绘图对象  
GDPdata=[[41.3,48.9,54.0,59.5,64.4,68.9,74.4]]  #准备绘图的序列数据
plt.plot(GDPdata,color="red",linewidth=2,linestyle='dashed',marker='o',label='GDP')    #绘图
#精细设置图元
plt.title('2010~2016 GDP: Trillion')
plt.xlim(0,7)          #x轴绘图范围
plt.ylim(40,75)      #y轴绘图范围
plt.xticks(range(0,7),('2010','2011','2012','2013','2014','2015','2016')) #将x轴刻度映射为字符串
plt.legend(loc='upper right')      #在右上角显示图例说明
plt.grid()       #显示网格线
plt.show()       #显示并关闭绘图

这样?

img

根据你的代码改了改:

import pandas as pd
import matplotlib.pyplot as plt

GDPdata = [41.3, 48.9, 54.0, 59.5, 64.4, 68.9, 74.4]

plt.figure()
plt.plot(GDPdata, color="red", linewidth=2, linestyle='dashed', marker='o', label='GDP')
plt.title('2010~2016 GDP: Trillion')
plt.xlim(0, 7)
plt.ylim(40, 75)
plt.xticks(range(0, 7), ('2010', '2011', '2012', '2013', '2014', '2015', '2016'))
plt.legend(loc='upper right')
plt.grid()
plt.show()


可能是因为matplotlib库没有正确安装,先试着运行一个最简单的 matplotlib 图形,如下:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

如果这个最简单的例子都不能运行,那么很可能是 matplotlib 安装不正确或者安装包不匹配系统,再次检查安装。

确认在运行这段代码时,matplotlib的版本是否正确,可以在运行这段代码之前,运行以下命令:

import matplotlib
print(matplotlib.__version__)

希望这些方法可以帮你解决问题