2

I've taken an image and extracted some features from it using OpenCv. I'd like to replot those points and their respective areas (which are real pixel values) into a scatter window and then save it. Unfortunately, when I plot the points, they resize to stay more visible. If I zoom in they resize. I'd like to save the whole figure retaining the actual ratio of pixel (x,y) coordinates to size of points plotted.

For instance:

import matplotlib.pyplot as plt   
x=[5000,10000,20000]
y=[20000,10000,5000]
area_in_pixels=[100,200,100]
scatter(x,y,s=area_in_pixels)

I would like this to produce tiny dots on the image. They should span like 10 xy units. However, the dots it produces are large, and appear to span 1000 xy units.

I've tried resizing the image with:

plt.figure(figsize=(10,10))

Which seems to resize the points relative to their position a little. But I'm not sure what scale I would select to make this accurate. DPI settings on plt.figsave seem to make the saved image larger but don't appear to alter relative spot sizes.

Asked another way, is there another way to relate the s which is in points^2 to a real number or to the units of the x-y axis?

Ionox
  • 45
  • 7
  • Have you considered using `plt.imshow`? Here's a [tutorial](http://matplotlib.org/users/image_tutorial.html). – wflynny Oct 28 '13 at 21:53
  • I had a related problem here: http://stackoverflow.com/questions/15160123/adding-a-background-image-to-a-plot-with-known-corner-coordinates – YXD Oct 28 '13 at 22:07

1 Answers1

4

You can use patches to create markers sized relative to the data coordinates.

import matplotlib.pyplot as plt   
from matplotlib.patches import Circle


xData=[5000,10000,20000, 15000]
yData=[20000,10000,5000, 15000]
radius_in_pixels=[100,200,100, 1000] # Circle takes radius as an argument. You could convert from area. 


fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')

for x, y, r in zip(xData, yData, radius_in_pixels):
    ax.add_artist(Circle(xy=(x, y), radius = r))      

plt.xlim(0, max(xData) + 200)
plt.ylim(0, max(yData) + 200)
plt.show()

scatter plot using circle patches

Molly
  • 13,240
  • 4
  • 44
  • 45