簡體   English   中英

使用PIL在地塊上顯示坐標

[英]show coordinates on plot using PIL

抱歉,我似乎找不到如何執行此操作。 這可行,但是我希望沿軸繪制坐標:

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

在此處輸入圖片說明

有人有建議嗎? 只是希望看到沿圖的垂直和水平方向的數字。 謝謝。

這是一種“強力”方法。 您可以將其概括化以更好地處理不同的x / y范圍。 也許您可以使用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