Instead, after adding all the polygons to a collection, use p = PatchCollection(patches)īut I still want to group polygons by color. I'll post the answer for anyone who may be having similar issues.įor some reason, setting the color in the polygon itself doesn't work. Okay, I figured out what I was trying to do. For now, just assume that poly_vertices is a list of polygon vertices, and poly_colors is a list of RGB colors and each list has 10000 entries.įor example: poly_vertices =, colors = Note that if you run this code, it won't work because poly_vertices and poly_colors haven't been defined. # I have a particular color for each polygon Patches.append(Polygon(poly_vertices, closed=True))Ĭolors.append(poly_colors) # This line is pointless, but I'm letting you know that Sample code: from llections import PatchCollection For me, each shape belonging to a particular group should have the same color. These solutions simply apply a random color to each shape in the list. How do I set color to Rectangle in Matplotlib? How to fill polygons with colors based on a variable in Matplotlib? Here are some posts I've found with similar issues to mine:įill polygons with multiple colors in python matplotlib I want to differentiate which group a polygon belongs to by mapping each unique group to a unique color. I have a list of 10,000+ Matplotlib Polygon objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |