环境:windows系统,anaconda3 64位,python 3.6python
基本代码以下:segmentfault
import numpy as np import matplotlib.pyplot as plt N = 1000 x = np.random.randn(N) y = np.random.randn(N) plt.scatter(x, y) plt.show()
这里使用numpy包的random
函数随机生成1000组数据,而后经过scatter函数绘制了散点图。windows
这篇文章的重点其实在于scatter
函数。
数组
c = 'r' (red); c = 'g' (green); c = 'k' (black) ; c = 'y'(yellow)
import numpy as np import matplotlib.pyplot as plt N = 1000 x = np.random.randn(N) y = np.random.randn(N) color = ['r','y','k','g','m'] plt.scatter(x, y,c=color,marker='>') plt.show()
import numpy as np import matplotlib.pyplot as plt N = 1000 x = np.random.randn(N) y = np.random.randn(N) plt.scatter(x, y,alpha=0.5) plt.show()
import numpy as np import matplotlib.pyplot as plt N = 1000 x = np.random.randn(N) y = np.random.randn(N) plt.scatter(x, y,alpha=0.5,edgecolors= 'white') #edgecolors = 'w',亦可 plt.show()
import numpy as np import matplotlib.pyplot as plt N = 1000 x = np.random.randn(N) y = np.random.randn(N) plt.scatter(x, y,alpha=0.5,edgecolors= 'white') plt.title('示例')#显示图表标题 plt.xlabel('x轴')#x轴名称 plt.ylabel('y轴')#y轴名称 plt.grid(True)#显示网格线 plt.show()
查找缘由,发现时由于matplotlib库没有中文字体。dom
每次编代码时都进行参数设置以下:函数
#coding:utf-8 import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 #有中文出现的状况,须要u'内容'
说实话,我折腾了半天没有成功,只有临时方法成功了。
等下次在尝试。3d
待续code