matplotlib中的legend()—显示图例
源自 matplotlib中的legend()——用于显示图例 -- 博客园 http://www.cnblogs.com/yinheyi/p/6792120.html
legend()的一个用法:
当我们有多个 axes时,我们如何把它们的图例放在一起呢??
我们可以这么做:
- import numpy as np
- x = np.arange(1, 11)
- fig = plt.figure(1)
- ax1 = plt.subplot(2, 1, 1)
- ax2 = plt.subplot(2, 1, 2)
- l1, = ax1.plot(x, x*x, 'r') #这里关键哦
- l2, = ax2.plot(x, x*x, 'b') # 注意
- plt.legend([l1, l2], ['first', 'second'], loc = 'upper right') #其中,loc表示位置的;
- plt.show()
在legend的参数中, loc参数设置图例的显示位置的:
- 'best' : 0, (only implemented for axes legends)(自适应方式)
- 'upper right' : 1,
- 'upper left' : 2,
- 'lower left' : 3,
- 'lower right' : 4,
- 'right' : 5,
- 'center left' : 6,
- 'center right' : 7,
- 'lower center' : 8,
- 'upper center' : 9,
- 'center' : 10,
另外,还有控制位置的重要参数:bbox_to_anchor(num1, num2), bbox_to_anchor被赋予的二元组中,第一个数值用于控制legend的左右移动,值越大越向右边移动,第二个数值用于控制legend的上下移动,值越大,越向上移动。
其它参数看这里有:
- Keyword
- Description
- loc
- a location code
- prop
- the font property (matplotlib.font_manager.FontProperties 对象)
- eg
- song_font = matplotlib.font_manager.FontProperties(fname='simsun.ttc', size=8)
- fontsize
- the font size (和prop互斥,不可同时使用)
- markerscale
- the relative size of legend markers vs. original
- numpoints
- the number of points in the legend for line
- scatterpoints
- the number of points in the legend for scatter plot
- scatteryoffsets
- a list of yoffsets for scatter symbols in legend
- frameon
- if True, draw a frame around the legend. If None, use rc
- fancybox
- if True, draw a frame with a round fancybox. If None, use rc
- shadow
- if True, draw a shadow behind legend
- ncol
- number of columns
- borderpad
- the fractional whitespace inside the legend border
- labelspacing
- the vertical space between the legend entries
- handlelength
- the length of the legend handles
- handleheight
- the length of the legend handles
- handletextpad
- the pad between the legend handle and text
- borderaxespad
- the pad between the axes and legend border
- columnspacing
- the spacing between columns
- title
- the legend title
- bbox_to_anchor
- the bbox that the legend will be anchored.
- bbox_transform
- the transform for the bbox. transAxes if None.
matplotlib中的legend()—显示图例的更多相关文章
- Matplotlib中中文不显示问题
我们在使用jupter进行数据分析的时候,会接触到Matplotlib这个库,它是用来进行可视化数据分析的,在一个图中,我们常常会加入一些中文来进行说明.当我们加入中文的时候会出现下图所示的样子: 可 ...
- python+NLTK 自然语言学习处理三:如何在nltk/matplotlib中的图片中显示中文
我们首先来加载我们自己的文本文件,并统计出排名前20的字符频率 if __name__=="__main__": corpus_root='/home/zhf/word' word ...
- matplotlib中的legend()——用于显示图例
legend()的一个用法: 当我们有多个 axes时,我们如何把它们的图例放在一起呢?? 我们可以这么做: import matplotlib.pyplot as plt import numpy ...
- Python Matplotlib 中对于 bar 显示时间的问题
参考: 官方教程: http://matplotlib.org/1.3.1/users/recipes.html http://stackoverflow.com/questions/13515471 ...
- matplotlib画图无法显示图例 报错No handles with labels found to put in legend.
很久没有matplotlib了,今天画图的时候发现了一个很小的问题....明明加了legend(),图表会出来,却无法正常显示图例.最后发现只要在plt.plot()加label图例就可以正常显示了.
- Matplotlib 中常见的图形
# 导包 from matplotlib import pyplot as plt import numpy as np 线性图 简单线性图 在图表的所有类型中,线性图最为简单.线性图的各个数据点由一 ...
- matplotlib中subplots的用法
1.matplotlib中如果只画一张图的话,可以直接用pyplot,一般的做法是: import matplotlib.pyplot as plt plt.figure(figsize=(20,8) ...
- matplotlib y轴标注显示不全以及subplot调整的问题
matplotlib y轴标注显示不全以及subplot调整的问题 问题: 我想在y轴显示的标注太长,想把它变成两行显示,发现生成的图形只显示的第二行的字,把第一行的字挤出去了 想要的是显示两行这样子 ...
- matplotlib 中的一些参数设置
首先:在pycharm 中要使图显示出来,最后一定要加上 plt.show(),如: plt.bar(x, y) plt.show() 下面就是我使用 matplotlib 遇到的一些常用参数设置: ...
随机推荐
- C++ 类的深拷贝和浅拷贝完美解决
//类的深拷贝和浅拷贝 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; class Poin ...
- ubuntu samba 安装
Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,是一种在局域网上共享文件和打印机的一种通信协议. 1. 安装 sudo apt-get install samba samba-c ...
- AWT是Java最早出现的图形界面,但很快就被Swing所取代
AWT是Java最早出现的图形界面,但很快就被Swing所取代. Swing才是一种真正的图形开发. AWT在不同平台所出现的界面可能有所不同:因为每个OS都有自己的UI组件库,java调用不同系统的 ...
- java-I/O File类(5)-Reader和Writer、OutputStreamWriter 、BufferedWriter、字节流和字符流的区别
标签: outputstreamwriterreader字符file方法 2015-05-14 23:06 469人阅读 评论(0) 收藏 举报 分类: 孙鑫-java基础(16) I-O(4 ...
- InstallSheild 获取系统环境变量,如Desktop路径等
使用FOLDER_DESKTOP变量获取的桌面路径可能为:C:\Users\Public\Desktop 而不是C:\Users\用户\Desktop Copy and paste the follo ...
- Linux环境下Apache配置多个虚拟主机挂载多站点同时运行
博客地址: http://blog.csdn.net/ClydeKuo/article/details/69569474 这篇博客讲的很详细,很详细.
- Spring学习笔记 7.1 Spring MVC起步
7.1.1 跟踪Spring MVC的请求请求首先到达DispatcherServlet(DispatcherServlet是Spring MVC中的前端控制器):DispatcherServlet的 ...
- 从远程(包括ftp,http等协议)地址获取文件流信息
URL url = new URL("ftp://172.18.251.155:8010/recordsImg/2019-01-28/000008_1548649813267.jpg&quo ...
- boost::lexical_cast
boost::lexical_cast为数值之间的转换(conversion)提供了一揽子方案,比如:将一个字符串"转换成整数123,代码如下: "; int a = lexica ...
- 【BZOJ4598】[Sdoi2016]模式字符串 树分治+hash
[BZOJ4598][Sdoi2016]模式字符串 Description 给出n个结点的树结构T,其中每一个结点上有一个字符,这里我们所说的字符只考虑大写字母A到Z,再给出长度为m的模式串s,其中每 ...