matplotlib(3)-- legend(图例、说明、解释),annotate(标注),text(标注)

 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3
 4 x = np.linspace(-3, 3, 50)
 5 y1 = 2 * x + 1
 6 y2 = x ** 2
 7
 8 plt.figure()
 9 l1, = plt.plot(x, y1, color = "red", linewidth = 5.0, linestyle = ‘--‘, label = ‘down‘)    #指定线的颜色, 宽度和类型
10 l2, = plt.plot(x, y2, label = "up")
11
12 #给figure添加legend(图例、说明、解释)
13 plt.legend(handles = [l1, l2], labels = ["y1 = 2 * x + 1", "y2 = x ** 2"], loc = "best")
14
15 plt.show()
 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3
 4 x = np.linspace(-3, 3, 50)
 5 y1 = 2 * x + 1
 6 X0 =1
 7 Y0 = 2 * X0 + 1
 8
 9 #figure 1
10 plt.figure()
11 plt.plot(x, y1)
12 plt.scatter(X0, Y0, s = 30, color = ‘black‘)     #在数据线上画点
13 plt.plot([X0, X0], [Y0, 0], color = "black", linewidth = 3.0, linestyle = ‘--‘)       #过一点做垂直于X轴的垂线
14
15 #坐标轴的移动 gca = “get current axis”
16 ax = plt.gca()
17 ax.spines["right"].set_color("none")
18 ax.spines["top"].set_color("none")
19 ax.xaxis.set_ticks_position("bottom")
20 ax.yaxis.set_ticks_position("left")
21 ax.spines["bottom"].set_position(("data", 0))   #Set the X and Y coordinates of the sprite simultaneously
22 ax.spines["left"].set_position(("data", 0))
23
24
25 #在figure上做标注的两种方法
26 #方法一
27 #关于annotate的相关参数介绍,参考博文 https://blog.csdn.net/leaf_zizi/article/details/82886755
28 ##########################
29 plt.annotate(r"$2*x_0 + 1 = %s$"%Y0, xy = (X0, Y0), xytext = (+30, -30),
30              textcoords = "offset points", fontsize = 16,
31              arrowprops = dict(arrowstyle = "->", connectionstyle = "arc3, rad=.2"))
32 #方法二
33 #补充:关于下角标的添加 “_+下角标字母”
34 #关于text的相关参数介绍,参考博文 https://blog.csdn.net/TeFuirnever/article/details/88947248
35 ##########################
36 plt.text(-3.7, 3, r"$This\ is\ y1 = 2 * x + 1\ \mu\ \sigma_i\ \alpha_t$",
37          fontdict={"size":16, "color":"red"})
38
39 plt.show()

原文地址:https://www.cnblogs.com/guoruxin/p/11247094.html

时间: 2024-07-28 22:35:44

matplotlib(3)-- legend(图例、说明、解释),annotate(标注),text(标注)的相关文章

matplotlib之legend

在<matplotlib极坐标系应用之雷达图> 中,我们提出了这个问题"图例中每种成员的颜色是怎样和极坐标相应的成员的颜色相对应的呢",那么接下来我们说说legend的一般使用和设置. 调用legend()一般有三种方式: 方式1. 自动检测,直接调用legend(); 在plot()时就指定图例labels,再直接调用legend()就好了,或者在plot中指定plot elements,然后通过set_label函数指定图例labels 1 plt.plot([1, 2

[Ext JS 4] Extjs 图表 Legend(图例)的分行与分列显示

Extjs 中的Chart 的legend. Legend, 翻译过来的意思是图例. 在Extjs 的Chart 中, 到底代表什么呢? 直接看这张图: 右边红色框起来的部分就是Legend 了. 在 Extjs Chart 的定义中, 可以通过配置 legend 的配置值(configs)来设置Legend 显示的位置和样式: position 配置显示的位置:可以设置的值有 "top","bottom", "left", "righ

Echarts (option.legend) 图例的属性,外部控制图例的select状态,以达到模拟图例的效果

先列举一些常用的属性: legend: { //图例,这里基本都是默认设置,就不一一列举,echarts 官网很好找 type: "plain", //'plain':普通图例.缺省就是普通图例.'scroll':可滚动翻页的图例.当图例数量较多时可以使用. show: true, //是否显示(隐藏和显示)柱子的那个按钮,默认true,如果不需要可以设置为false.如果没有请忽略. selectedMode: true, //图例上的点击事件,不写默认true ,设置false为不

百度地图API 添加自定义标注 多点标注

原文:百度地图API 添加自定义标注 多点标注 分四个文件 location.php map.css 图片 数据库 数据库配置自己改下 ------------------------------------------------------------  华丽的分割线   ----------------------------------------------------- location.php 主文件 <link rel="stylesheet" type=&quo

Legend 图例

1.添加图例 >>> import matplotlib.pyplot as plt >>> import numpy as np >>> x = np.linspace(-3, 3, 50) >>> y1 = 2*x + 1 >>> y2 = x**2 >>> plt.figure() <Figure size 640x480 with 0 Axes> >>> plt

4.11Python数据处理篇之Matplotlib系列(十一)---图例,网格,背景的设置

目录 目录 前言 (一)图例legend 1.默认不带参数的图例 2.添加参数的图例 3.将图例移动到框外 (二)网格grid 1.说明 2.源代码: 3.输出效果 (三)背景axses 1.设置全局的背景色: 2.设置局部的背景色 目录 前言 本章节将讲一下三个内容,图例,网格,背景 (一)图例legend 1.默认不带参数的图例 (1)说明: 默认情况下,是自适应的放在图例的位置,需要在绘图的时候,添加Label标识. 在使用plt.legend()显示图例 (2)源代码: # 导入模块 i

Hadoop Serialization -- hadoop序列化具体解释 (2)【Text,BytesWritable,NullWritable】

回想: 回想序列化,事实上原书的结构非常清晰,我截图给出书中的章节结构: 序列化最基本的,最底层的是实现writable接口,wiritable规定读和写的游戏规则 (void write(DataOutput out) throws IOException;  void readFields(DataInput in) throws IOException;).为了适应hadoop的mapreduce的运算特性,也就是map 和reduce对key的比較,排序的功能,就要实现Comparabl

python 2: 解决python中的plot函数的图例legend不能显示中文问题

 问题: 图像标题.横纵坐标轴的标签都能显示中文名字,但是图例就是不能显示中文,怎么解决呢?  解决: 1 plt.figure() 2 plt.title(u'训练性能', fontproperties=font) 3 plt.plot(history.epoch, history.history['loss'], label=u'训练误差') 4 plt.plot(history.epoch, history.history['val_loss'], label=u'验证误差') 5 plt

ggplot2-设置图例(legend)

本文更新地址:http://blog.csdn.net/tanzuozhev/article/details/51108040 本文在 http://www.cookbook-r.com/Graphs/Scatterplots_(ggplot2)/ 的基础上加入了自己的理解 图例用来解释图中的各种含义,比如颜色,形状,大小等等, 在ggplot2中aes中的参数(x, y 除外)基本都会生成图例来解释图形, 比如 fill, colour, linetype, shape. 基本箱线图(带有图例

matplotlib的学习5-legend图例

import matplotlib.pyplot as plt import numpy as np ''' legend 图例就是为了帮我们展示出每个数据对应的图像名称. 更好的让读者认识到你的数据结构. ''' x = np.linspace(-3, 3, 50) y1 = 2*x + 1 y2 = x**2 plt.figure() #set x limits plt.xlim((-1, 2)) plt.ylim((-2, 3)) # set new sticks new_sticks =