python能画的图种类非常多,而且看上去都很好看,具体种类部分可参看:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure

这里主要是探索下散点图绘制。

1. 首先是导入包,创建数据

importmatplotlib.pyplot as pltimportnumpy as np

n = 10

x= np.random.rand(n) * 2 #随机产生10个0~2之间的x坐标

y = np.random.rand(n) * 2 #随机产生10个0~2之间的y坐标

2. 创建一张figure

fig = plt.figure(1)

3. 设置颜色 color 值【可选参数,即可填可不填】,方式有几种

#colors = np.random.rand(n) # 随机产生10个0~1之间的颜色值,或者

colors = ['r', 'g', 'y', 'b', 'r', 'c', 'g', 'b', 'k', 'm'] #可设置随机数取

4. 设置点的面积大小 area 值 【可选参数】

area = 20*np.arange(1,n+1)

5. 设置点的边界线宽度 【可选参数】

widths = np.arange(n) #0-9的数字

6. 正式绘制散点图:scatter

plt.scatter(x, y, s=area, c=colors, linewidths=widths, alpha=0.5, marker='o')

其参数主要有:

def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,

vmin=None, vmax=None, alpha=None, linewidths=None,

verts=None, edgecolors=None,**kwargs):"""A scatter plot of *y* vs *x* with varying marker size and/or color.

Parameters

----------

x, y : array_like, shape (n, )

The data positions.

s : scalar or array_like, shape (n, ), optional

The marker size in points**2.

Default is ``rcParams['lines.markersize'] ** 2``.

c : color, sequence, or sequence of color, optional, default: 'b'

The marker color. Possible values:

- A single color format string.

- A sequence of color specifications of length n.

- A sequence of n numbers to be mapped to colors using *cmap* and

*norm*.

- A 2-D array in which the rows are RGB or RGBA.

Note that *c* should not be a single numeric RGB or RGBA sequence

because that is indistinguishable from an array of values to be

colormapped. If you want to specify the same RGB or RGBA value for

all points, use a 2-D array with a single row.

marker : `~matplotlib.markers.MarkerStyle`, optional, default: 'o'

The marker style. *marker* can be either an instance of the class

or the text shorthand for a particular marker.

See `~matplotlib.markers` for more information marker styles.

cmap : `~matplotlib.colors.Colormap`, optional, default: None

A `.Colormap` instance or registered colormap name. *cmap* is only

used if *c* is an array of floats. If ``None``, defaults to rc

``image.cmap``.

alpha : scalar, optional, default: None

The alpha blending value, between 0 (transparent) and 1 (opaque).

linewidths : scalar or array_like, optional, default: None

The linewidth of the marker edges. Note: The default *edgecolors*

is 'face'. You may want to change this as well.

If *None*, defaults to rcParams ``lines.linewidth``.

7. 设置轴标签:xlabel、ylabel

#设置X轴标签

plt.xlabel('X坐标')#设置Y轴标签

plt.ylabel('Y坐标')

8. 设置图标题:title

plt.title('test绘图函数')

9. 设置轴的上下限显示值:xlim、ylim

#设置横轴的上下限值

plt.xlim(-0.5, 2.5)#设置纵轴的上下限值

plt.ylim(-0.5, 2.5)

10. 设置轴的刻度值:xticks、yticks

#设置横轴精准刻度

plt.xticks(np.arange(np.min(x)-0.2, np.max(x)+0.2, step=0.3))#设置纵轴精准刻度

plt.yticks(np.arange(np.min(y)-0.2, np.max(y)+0.2, step=0.3))

也可按照xlim和ylim来设置

#设置横轴精准刻度

plt.xticks(np.arange(-0.5, 2.5, step=0.5))#设置纵轴精准刻度

plt.yticks(np.arange(-0.5, 2.5, step=0.5))

11. 在图中某些点上(位置)显示标签:annotate

#plt.annotate("(" + str(round(x[2],2)) +", "+ str(round(y[2],2)) +")", xy=(x[2], y[2]), fontsize=10, xycoords='data') #或者

plt.annotate("({0},{1})".format(round(x[2],2), round(y[2],2)), xy=(x[2], y[2]), fontsize=10, xycoords='data')#xycoords='data' 以data值为基准#设置字体大小为 10

12. 在图中某些位置显示文本:text

plt.text(round(x[6],2), round(y[6],2), "good point", fontdict={'size': 10, 'color': 'red'}) #fontdict设置文本字体#Add text to the axes.

13. 设置显示中文

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签

plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

14. 设置legend,【注意,'绘图测试’:一定要是可迭代格式,例如元组或者列表,要不然只会显示第一个字符,也就是legend会显示不全】

plt.legend(['绘图测试'], loc=2, fontsize = 10)#plt.legend(['绘图测试'], loc='upper left', markerscale = 0.5, fontsize = 10) #这个也可#markerscale:The relative size of legend markers compared with the originally drawn ones.

其参数loc对应为:

15. 保存图片 savefig

plt.savefig('test_xx.png', dpi=200, bbox_inches='tight', transparent=False)#dpi: The resolution in dots per inch,设置分辨率,用于改变清晰度#If *True*, the axes patches will all be transparent

16. 显示图片 show

plt.show()

结果如下:

##

参考:

https://blog.csdn.net/u014636245/article/details/82799573

https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure

https://www.jianshu.com/p/78ba36dddad8

https://blog.csdn.net/u010852680/article/details/77770097

https://blog.csdn.net/u013634684/article/details/49646311

scatter python_Python的散点图绘制 scatter相关推荐

  1. plotly基于dataframe数据绘制散点图(scatter plot)

    plotly基于dataframe数据绘制散点图(scatter plot) # 读取沪深300和上证50的数据: # 绘制散点图: import plotly as py # 导入plotly库并命 ...

  2. cufflinks基于dataframe数据绘制股票数据:散点图(scatter plot)、价差图

    cufflinks基于dataframe数据绘制金融数据:散点图(scatter plot).价差图 # 散点图 from chart_studio import plotly as py impor ...

  3. cufflinks基于dataframe数据绘制线图(line plot)、散点图(scatter plot)

    cufflinks基于dataframe数据绘制线图(line plot).散点图(scatter plot) # cufflinks绘制线图(line plot) from chart_studio ...

  4. MATLAB~~~描绘散点图函数scatter

    1.scatter(X,Y) X和Y是数据向量,以X中数据为横坐标,以Y中数据位纵坐标描绘散点图,点的形状默认使用圈. >> x=[7 8 9 4 5 6 ] x = 7     8   ...

  5. Python数据可视化的例子——散点图(scatter)

    (关系型数据的可视化) 散点图用于发现两个数值变量之间的关系 如果需要研究两个数值型变量之间是否存在某种关系,例如正向的线性关系,或者是趋势性的非线性关系,那么散点图将是最佳的选择. 1.matplo ...

  6. scatter python_Python中scatter函数参数及用法详解

    最近开始学习Python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...

  7. scatter python cmap_使用matplotlib中scatter方法画散点图

    本文实例为大家分享了用matplotlib中scatter方法画散点图的具体代码,供大家参考,具体内容如下 1.最简单的绘制方式 绘制散点图是数据分析过程中的常见需求.python中最有名的画图工具是 ...

  8. scatter python_python中的scatter()方法

    1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如下: 4.基本的使用方法如下: #导入必要的模块 importnumpy as np importmatplo ...

  9. R语言ggplot2可视化散点图(scatter plot)、并在可视化图像的顶部和右边添加边缘直方图(Marginal Histogram)、使用geom_smooth函数基于lm方法拟合数据点之间

    R语言ggplot2可视化散点图(scatter plot).并在可视化图像的顶部和右边添加边缘直方图(Marginal Histogram).使用geom_smooth函数基于lm方法拟合数据点之间 ...

最新文章

  1. navicat的使用
  2. 客户端AJAX验证表单
  3. linux有三个查看文件的命令:more、cat、less
  4. vmware添加新硬盘 挂载新硬盘 硬盘扩容
  5. Window 消息大全使用详解(无聊没事做)
  6. SAP在物流工作中的应用之学习笔记
  7. SaaS新模式:业务、财务与支付无缝对接
  8. HTML5如何学?学HTML5要注意什么?
  9. AAAI 2019 滴滴被收录论文全解读
  10. python解释器的提示符是shell嘛_从PowerShell语法错误运行Python脚本
  11. 汇顶科技【软件工程师】面经
  12. 用matlab开发软件开发,Matlab软件应用与开发new
  13. SVG添加链接(转载)
  14. VHDL——74LS138译码器
  15. Odoo CRM获福布斯评为《2022最佳开源CRM》
  16. 各大城市值得加入的互联网公司有哪些?
  17. python快速实现数字华容道小游戏
  18. 学习笔记:12864液晶模块的…
  19. matlab学习笔记9 高级绘图命令_2 图形的高级控制_视点控制和图形旋转_色图和颜色映像_光照和着色
  20. 字字珠玑的百度员工离职总结

热门文章

  1. 高压MOSFET控制器简化非隔离开关的设计
  2. 电子发票的高速发展,带给费控报销信息化领域怎样的变革?
  3. 解决[服务器证书无效, 连接伪装服务器]问题
  4. 【前端做项目常用】相关插件的官网 总结
  5. 如何检查SMC存储卡有非一致性或者是格式错误以及修复的方法?
  6. 【微信小程序】狮子鱼社区团购小程序V9.9.0完整前后端安装包+小程序前端
  7. c#: Noto Sans字体如何支持韩文
  8. redis ,redisson 分布式锁深入剖析
  9. linux之sudo apt-get install
  10. 手机算是计算机网络中的计算机么,手机是计算机吗