用pyplot绘制一个单调递减的折线图
时间: 2023-06-17 20:03:49 浏览: 52
好的,以下是绘制单调递减折线图的示例代码:
```python
import matplotlib.pyplot as plt
# 准备数据
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
# 绘制折线图
plt.plot(x, y)
# 设置图表标题和坐标轴标签
plt.title("Monotonic Decreasing Line Graph", fontsize=16)
plt.xlabel("X-axis", fontsize=12)
plt.ylabel("Y-axis", fontsize=12)
# 设置刻度标记的大小
plt.tick_params(axis='both', which='major', labelsize=10)
# 显示图形
plt.show()
```
运行代码后,会弹出一个窗口显示绘制的单调递减折线图。如下图所示:
![monotonic-decreasing-line-graph](https://img-blog.csdnimg.cn/20210925023920153.png)
相关问题
python用pyplot绘制折线图的代码
以下是使用pyplot绘制折线图的代码示例:
``` python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
plt.plot(x, y)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Line Chart example")
plt.show()
```
这段代码可以实现在一个坐标系上绘制出给定数据的折线图,并且添加了X轴、Y轴的标签和标题。
matplotlib.pyplot绘制折线图代码
下面是一个简单的 matplotlib.pyplot 绘制折线图的代码示例:
```python
import matplotlib.pyplot as plt
# x 和 y 数据
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# 绘制折线图
plt.plot(x, y)
# 添加标题和标签
plt.title("折线图示例")
plt.xlabel("X 轴")
plt.ylabel("Y 轴")
# 显示图形
plt.show()
```
这段代码将会绘制一个简单的折线图,其中 x 轴表示 1 到 5 的整数,y 轴表示 2 到 10 的整数。您可以根据需要修改 x 和 y 数据,以及标题和标签。