Python 画图加坐标,加点,加网格

import matplotlib.pyplot as plt

y= read_predictdatas('文件名.csv') #这里的read_predictdatas函数是自己写的,用来读取数据

y = origianl- predictdatas
x = [i for i in  range(len(difference))]

#给每个点加坐标
for a, b in zip(i, difference):
 plt.text(a, b, (a, b), ha='center', va='bottom', fontsize=10)
 
#显示网格
plt.grid(True) 

#加点,设置点的颜色为红色
plt.plot(x, y, marker='o', markerfacecolor='red')

#画散点图
plt.scatter(x, y, marker='o'')

plt.show()

在这里插入图片描述

加水平和垂直的线
vlines(x, ymin, ymax)
hlines(y, xmin, xmax)
plt.vlines(0, 0, 0.5, colors = "r", linestyles = "dashed")

画子图

plt.plot(2,2,1)
plt.plot(2,2,2)
plt.plot(2,1,2)
plt.show()

在这里插入图片描述
画子图参考链接

  • 5
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python中有很多库可以用来画图,其中比较常用的是matplotlib库。在matplotlib中,可以使用subplot函数来实现网格布局,即将一个画布分割成多个子图。可以通过调整subplot函数的参数来设置网格的行数、列数和子图位置。 下面是一个简单的例子,展示了如何使用matplotlib库在网格绘制图形: ```python import matplotlib.pyplot as plt # 创建一个2行2列的网格布局,并选择第一个子图作为当前绘图对象 plt.subplot(2, 2, 1) # 在当前子图中绘制一条直线 plt.plot([0, 1], [0, 1]) # 选择第二个子图作为当前绘图对象,并设置标题 plt.subplot(2, 2, 2) plt.title('Title of subplot 2') # 在当前子图中绘制一条曲线 x = [i for i in range(10)] y = [i**2 for i in x] plt.plot(x, y) # 选择第三个子图作为当前绘图对象,并设置坐标轴标签 plt.subplot(2, 2, 3) plt.xlabel('X label of subplot 3') plt.ylabel('Y label of subplot 3') # 在当前子图中绘制一张图片 img = plt.imread('image.jpg') plt.imshow(img) # 显示所有子图 plt.show() ``` 在上面的代码中,我们先使用subplot函数创建了一个2行2列的网格布局,并选择第一个子图作为当前绘图对象。接着,在当前子图中绘制了一条直线。然后,我们选择第二个子图作为当前绘图对象,并设置了一个标题。在第二个子图中,我们绘制了一条曲线。接着,我们选择第三个子图作为当前绘图对象,并分别设置了X轴和Y轴的标签。最后,在第三个子图中,我们显示了一张图片。最后,我们调用show函数显示所有子图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值