python画曲线图添加网格线,在matplotlib中的图像上绘制网格线

本文介绍如何在Python中利用matplotlib库在一张tif图像上绘制网格线,并在每个网格中心添加编号。首先确保安装了PIL库,然后打开图像文件,设置网格间隔,添加网格线,并在每个网格中心用白色文字标注编号。最后,保存带有网格的图像。
摘要由CSDN通过智能技术生成

How can I draw regular grid lines over a tiff image?

I want to draw regular square grids for each interval (say 100 by 100 pixels) over the image and save that with the drawings. I also need to overlay each grid id as '1','2',...at the middle of each grid box.

解决方案

You will need the python imaging library (PIL) installed. (See here https://pypi.python.org/pypi/PIL). See these answers for examples of ways to install PIL: answer 1, answer 2

Right, with that installed, the following code should do what you ask for:

import matplotlib.pyplot as plt

import matplotlib.ticker as plticker

try:

from PIL import Image

except ImportError:

import Image

# Open image file

image = Image.open('myImage.tiff')

my_dpi=300.

# Set up figure

fig=plt.figure(figsi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值