1

I was following this: Create random shape/contour using matplotlib

and I wanted to fill the generated shapes with certain values. Problem is I am only given the x & y coordinates of the shape outline. How can I populate the space in the random shape with values?

Let's say i have a function f(x,y) that takes in x and y values to give an output z. I want to populate the space in the shape with the value z.

Example of shape:

enter image description here

Zack
  • 21
  • 2
  • Matplot has an API for that, which showed up first in my Google search. https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.fill.html – Tim Roberts Mar 28 '22 at 20:39
  • Sorry i should have been more clear. let's say i have a function f(x,y) that takes in x and y values to give an output z. I want to populate the space in the shape with the value z. – Zack Mar 28 '22 at 20:55
  • *with the value z* -- What do you mean? Do want a 3D plot, or do you want the color to be based on z? You can do the latter with `pyplot.scatter`. – Tim Roberts Mar 28 '22 at 21:00
  • Essentially I want a 2D array of values based on a function z = f(x,y). What I have now is the x and y values corresponding to the shape outline. I want to fill the shape based on z, which is based on f(x,y). In other words, I want to get the list of x & y values inside the polygon. – Zack Mar 28 '22 at 21:06
  • That's tough. You're talking about a flood fill algorithm. It might be easier to get a snapsshot of that plot, then scan it by scanlines to determine which coordinates are in or out. – Tim Roberts Mar 28 '22 at 22:06
  • After many trials and error, I think I figured it out using Shapely. I manage to create a mask or 0s and 1s, so I should be able to use them to do my task. Thanks for the help. – Zack Mar 28 '22 at 22:22

0 Answers0