If for example, I have the following coordinates with corresponding colors which represent a hexagonal shaped grid of hexagons:
coord = [[0,0,0],[0,1,-1],[-1,1,0],[-1,0,1],[0,-1,1],[1,-1,0],[1,0,-1]]
colors = [["Green"],["Blue"],["Green"],["Green"],["Red"],["Green"],["Green"]]
How can one plot this in Python so that the points on the plot retain that hexagonal shape? Additionally how can one represent the 'colors' list on the hexagon.
Somewhat like this:
Simple Hexagonal grid
But the look doesn't matter, just a simple scatter plot type visualization would suffice, just so that one can see where in relation to other hexagons the colors lie.
Below is my attempt to finish PM2Ring's turtle-based solution (+1) as well as fix what I see as a coordinate calculation error in his answer:
Here's a function that converts a (u, v, w) tuple of hex coordinates into rectangular coordinates. I'll illustrate it using the standard
turtle
module (I don't have the matplotlib module). I've changed the colours on the list so we can easily check that each point is plotted in the correct position.output
You just need to turn the
(y, z)
coordinates from your hexagons into they
cartesian coordinate on the matplotlib axes.I think the correct way to do that is using this formula:
You can then add the hexagons using a matplotlib
RegularPolygon
patch, or plot the centres usingscatter
.Here's a script to make a plot from your lists: