前记:由于python大二在看,半途写了一些入门代码,不过很快忘了,中间上课偶尔又在看一本叫什么 Python-cook book的书,就一直没有丢,但是又一直没进化这门语言的能力;python 就是适合处理数据,他的数据结构真的很简单,而且对于分析者用法透明;越说越激动了,开始调库吧!安装就不用说了;
这此就是一个简单的代码,调库就是这么简单粗暴,实现以下的可视化,生成 x的平方曲线,后面代码你能看出这个其实是密集的散列点组成的曲线:
Generate data ,square:
最简单的:
import matplotlib.pyplot as plt squares = [1,4,9,16,25] inputvalues =[1,2,3,4,5] plt.plot(inputvalues,squares, linewidth=5) # 设置图表标题,并给坐标轴加上标签 plt.title("Square Numbers", fontsize=24) plt.xlabel("Value", fontsize=14) plt.ylabel("Square of Value", fontsize=14) # 设置刻度标记的大小 plt.tick_params(axis='both', labelsize=14) plt.show()第二个代码;
稍微加入了部分配置,也就是你看见的上面的图:
#绘制散列点 import matplotlib.pyplot as mpt x_values =list(range(1,1001)) y_values = [x**2 for x in x_values] #将c设置为y的值则按照其渐变 mpt.scatter(x_values,y_values,c=y_values,cmap=mpt.cm.Blues,edgecolors='none',s=1) mpt.axis([0,1100,0,1100000]),设置坐标轴 mpt.title("Square Numbers", fontsize=24) mpt.xlabel("Value", fontsize=14) mpt.ylabel("Square of Value", fontsize=14) # 设置刻度标记的大小 mpt.tick_params(axis='both', which='major', labelsize=14) mpt.savefig('my.png',bbox_inches='tight') mpt.show() mpt.scatter(x_values,y_values,c=y_values,cmap=mpt.cm.Blues,edgecolors='none',s=1)这行代码就是主要的,x,y都是数组,c是渐变的参数,cmap就是设置颜色,s是散列点的大小
@_autogen_docstring(Axes.scatter) def scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs): ax = gca() # Deprecated: allow callers to override the hold state # by passing hold=True|False点开源码还有更多参数;alpha透明度,