对于y轴范围设置的更多例子
时间: 2023-12-20 11:16:34 浏览: 29
好的,以下是一些y轴范围设置的例子:
1. 设置y轴范围为0到100:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [20, 50, 70, 90, 100]
plt.plot(x, y)
plt.ylim(0, 100)
plt.show()
```
2. 自动调整y轴范围:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [20, 50, 70, 90, 100]
plt.plot(x, y)
plt.ylim('auto')
plt.show()
```
3. 设置y轴范围为最小值-10到最大值+10:
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.ylim(y.min()-10, y.max()+10)
plt.show()
```
希望这些例子对你有所帮助!
相关问题
R语言 plot函数对于y轴范围设置的更多例子
好的,以下是一些R语言中plot函数对于y轴范围设置的例子:
1. 设置y轴范围为0到100:
```R
x <- c(1, 2, 3, 4, 5)
y <- c(20, 50, 70, 90, 100)
plot(x, y, ylim = c(0, 100))
```
2. 自动调整y轴范围:
```R
x <- c(1, 2, 3, 4, 5)
y <- c(20, 50, 70, 90, 100)
plot(x, y, ylim = "auto")
```
3. 设置y轴范围为最小值-10到最大值+10:
```R
x <- seq(0, 2*pi, length.out = 100)
y <- sin(x)
plot(x, y, ylim = c(min(y)-10, max(y)+10))
```
希望这些例子对你有所帮助!
R语言 plot函数对于y轴刻度设置的更多例子
好的,以下是一些R语言中plot函数对于y轴刻度设置的例子:
1. 设置y轴刻度为1:
```R
x <- c(1, 2, 3, 4, 5)
y <- c(20, 50, 70, 90, 100)
plot(x, y, ylim = c(0, 100), yaxp = c(0, 100, 1))
```
2. 设置y轴刻度为自定义的值:
```R
x <- c(1, 2, 3, 4, 5)
y <- c(20, 50, 70, 90, 100)
plot(x, y, ylim = c(0, 100), yaxt = "n")
yaxis <- seq(0, 100, by = 20)
axis(2, at = yaxis)
```
3. 设置y轴刻度为对数刻度:
```R
x <- c(1, 2, 3, 4, 5)
y <- c(1, 10, 100, 1000, 10000)
plot(x, y, log = "y")
```
希望这些例子对你有所帮助!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)