简体   繁体   English

使用PIL在地块上显示坐标

[英]show coordinates on plot using PIL

I'm sorry, I can't seem to find how to do this. 抱歉,我似乎找不到如何执行此操作。 This works, but I would love to have the coordinates plotted along the axis: 这可行,但是我希望沿轴绘制坐标:

from PIL import Image, ImageDraw
im = Image.new('RGBA', (250, 250), "white")
draw = ImageDraw.Draw(im)
draw.rectangle([(0, 0), (249, 249)], outline='black')  # just here to create a visible box
draw.rectangle([(10, 40), (100, 200)], fill='red', outline='red')
im

在此处输入图片说明

Does anyone have any advice? 有人有建议吗? Just would love to see numbers along the vertical and horizontal components of the plot. 只是希望看到沿图的垂直和水平方向的数字。 Thanks. 谢谢。

Here is a "brute force" way to do this. 这是一种“强力”方法。 You could generalize it to better handle different x/y ranges. 您可以将其概括化以更好地处理不同的x / y范围。 Maybe you could use matplotlib and potentially go off this example 也许您可以使用matplotlib并可能退出本示例

from PIL import Image, ImageDraw
im = Image.new('RGBA', (250, 250), "white")
draw = ImageDraw.Draw(im)
draw.rectangle([(0, 0), (249, 249)], outline='black')  # just here to create a visible box
draw.rectangle([(10, 40), (100, 200)], fill='red', outline='red')
# Draw x ticks
[draw.line(((x,250),(x,245)),fill='black') for x in range(0,249,5)]
# Draw x labels
[draw.text((x,235),str(x),fill='black')for x in range(0,249,25)]
# Can do same for y...
im

非常基本的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM