i'm doing illustrations paper in python using matplotlib
library. in illustration have lot of lines, polygons, circles etc. want insert .png
image outside.
here's i'm trying far:
import matplotlib.pyplot plt import numpy np matplotlib.patches import polygon fig, ax = plt.subplots() plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off') ax.axis('off') # drawing circle ax.add_patch( plt.circle((0, 0), 0.5, color = 'black') ) # drawing polygon ax.add_patch( polygon( [[0,0], [20, 15], [20, 40]], closed=true, fill=false, lw=1) ) # importing image im = plt.imread("frame.png") # defining image position/size rect = 0.5, 0.4, 0.4, 0.4 # should these values be? newax = fig.add_axes(rect, anchor='ne', zorder=1) newax.imshow(im) newax.axis('off') ax.set_aspect(1) ax.set_xlim(0, 60) ax.set_ylim(0, 40) plt.show()
so question is, how determine values rect = 0.5, 0.4, 0.4, 0.4
? e.g., want lower left corner of .png
@ point [20, 15]
, want height 25
.
this resulting image:
but want dummy frame adjusted polygon points, (this one's adjusted in photoshop):
p.s. here link frame.png
experiment with.
can plot lines , picture on same axis? that, use extent
key in plt.imshow()
import numpy np import matplotlib.pyplot plt matplotlib.patches import polygon im='d:/frame.png' img=plt.imread(im) fig, ax = plt.subplots() frame_height=25 x_start=20 y_start=15 ax.imshow(img,extent=[x_start,x_start+frame_height,y_start,y_start+frame_height]) ax.add_patch( polygon( [[0,0], [20, 15], [20, 40]], closed=true, fill=false, lw=1) ) ax.set_xlim(0, 60) ax.set_ylim(0, 40) plt.show()
Comments
Post a Comment