python label参数,python-matplotlib库label函数参数即使用

本文演示了Python的matplotlib库中label函数的使用,包括绘制图表、设置坐标轴范围、自定义刻度标签、调整坐标轴边框等,帮助理解label参数在图形中的作用。

python-matplotlib库label函数参数即使用

```python

import matplotlib.pyplot as plt

import numpy as np

# 定义数据

x = np.linspace(-3, 3, 50)

y1 = 2*x + 1

y2 = x**2

# 定义figure

plt.figure()

# 绘图(x,y2)

plt.plot(x, y2)

# 绘图(x,y1)

plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')

# 设置坐标返回

plt.xlim((-1, 2))

plt.ylim((-2, 3))

# 设置x轴刻度 这里分为5个小刻度

new_ticks = np.linspace(-1, 2, 5)

print(new_ticks)

plt.xticks(new_ticks)

# 设置y轴刻度,这里将刻度以自定义的数字表示出来,比如-2显示为really bad

# 使用$来更好的匹配文本以及字体,$\pi$则会显示Pi

plt.yticks([-2, -1.8, -1, 1.22, 3],

[r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])

# 得到坐标轴信息

ax = plt.gca()

# .spines设置边框;set_color设置颜色

# 将上方和右边的坐标线取消

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')

# 设置x轴刻度位置,这里刻度在下方,

# 具体有[ 'top' | 'bottom' | 'both' | 'default' | 'none' ]

ax.xaxis.set_ticks_position('bottom')

# 设置边框位置,下方的边框位于y=0处,

# 具体有'outward' | 'axes' | 'data'

# axes: percentage of y axis

# data: depend on y data

ax.spines['bottom'].set_position(('data', 0))

# y轴刻度在左侧

# 具体有[ 'left' | 'right' | 'both' | 'default' | 'none' ]

ax.yaxis.set_ticks_position('left')

# 左侧边框在x=0处

ax.spines['left'].set_position(('data', 0))

plt.show()

```

python-matplotlib库label函数参数即使用 相关文章

python里面的函数定义与使用

~什么是函数 !函数是一段具有特定功能的、可重用的语句组,是一种功能的抽象。一般函数表达特定功能。 ~它的一般表示形式为: def 函数名(参数): 函数体 return 返回值 注意:上面的参数可有可无,但是我们括号一定得有。 示例: def fact(n):s=1for i in r

async 函数简单介绍 (async、await关键字)

详细文档:ECMAScript 6 async 函数(阮一峰) 介绍 ES2017 标准引入了 async 函数,使得异步操作变得更加方便。async 函数是什么一句话,它就是 Generator 函数的语法糖。 // 请求网络数据(伪代码)// generator 函数const requestDataGenerator = functio

js 递归

递归会形成递归栈,栈顶是满足条件的最后一个函数,当这个函数出栈之后,倒数第二个栈的代码继续执行。(因为代码没执行完呢) 函数递归回来的结果值通常要保存或者赋值。这个很重要 递归不是闭包。 //5*4*3*2*1=120 //f5=5*f4 f4=4*f3 f3=3*f2 f2=2*f1 f1=1

(python函数04)zip(*sorted(zip()))

zip(*sorted(zip())) 用这个玩意儿可以以对两个迭代对象进行排序。 示例代码01 cnts = [2, 4, 3, 6, 5] boundingBoxes = [(730, 20, 54, 85), (651, 20, 53, 85), (571, 20, 53, 85), (492, 20, 53, 85), (412, 20, 53, 85)] ? # b是zip中的一个元素,不确定

js递归

函数内部直接或间接调用函数本身为递归 递归求阶乘 function factorial(num) { // 0的阶乘等于1 // 递归最重要的是明确递归结束条件,避免爆栈(RangeError: Maximum call stack size exceeded) if (num === 0) return 1; return num * factorial(num -1);}co

代码审计学习01-in_array() 函数缺陷

一、开始代码审计之旅 01 从今天起,学习代码审计了,这篇文章就叫代码审计01吧,题目来自PHP SECURITY CALENDAR 2017的第一题,结合红日安全写的文章,开始吧。 二、先看这道题目 1、题目名称:Wish List 2、in_array() 函数的作用 in_array() 函数的作用是

关于strsep函数以及联想

今天在调用strsep函数时,报了Segmentation fault错误,strsep函数原型如下: char *strsep(char **stringp, const char *delim); 第一个参数是个二级指针,而且没有const修饰,我猜测在man手册中只要是添加const修饰的参数都是只读的(当然这是肯定的),而

C# 类 构造函数的执行顺序

namespace Temp{ class Program { static void Main(string[] args) { Class1 c = new Class1(); } } class BaseClass { int z = 3; public BaseClass() { Demo(); } public virtual void Demo() { Console.WriteLine("BaseClass.Demo"); } } class Class1 :

opencv函数学习:cvtColor()的使用

cvtColor() 官方使用说明 void cv::cvtColor(InputArraysrc,OutputArraydst,intcode,intdstCn= 0) #include opencv2/imgproc.hpp Converts an image from one color space to another. The function converts an input image from one color space to anothe

Linux 库函数与系统调用

上周总结了《C 标准库的基础 IO》,其实这些功能函数通过「系统调用」也能实现相应功能。这次文章并不是要详细介绍各系统调用接口的使用方法,而是要深入理解「库函数」与「系统」调用之间的关系和区别。 一、系统调用 系统调用,我们可以理解是操作系统为用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值