I want to plot a 2D grid (24x4) where each grid coordinates have a value, the data is in a dict as such:
{map1_ID:[
['x_coor','y_coor','data_to plot'],
['x_coor','y_coor','data_to plot'],
...
],
map2_ID:[
['x_coor','y_coor','data_to plot'],
['x_coor','y_coor','data_to plot'],
...
]}
How can I do that using matplotlib or any other library in python?
CodePudding user response:
Plotly is my go-to for any kind of figure. This is a rough version of what you're looking for.
import plotly.graph_objects as go
maps = {'map1_ID': [[0, 0, 1], [0, 1, 1], [0, 2, 10], [0, 3, 1], [1, 0, 1], [1, 1, 1], [1, 2, 14], [1, 3, 1], [2, 0, 1], [2, 1, 1], [2, 2, 10], [2, 3, 1], [3, 0, 1], [3, 1, 1], [3, 2, 10], [3, 3, 1], [4, 0, 1], [4, 1, 1], [4, 2, 10], [4, 3, 1], [5, 0, 1], [5, 1, 1], [5, 2, 10], [5, 3, 1], [6, 0, 1], [6, 1, 1], [6, 2, 10], [6, 3, 1], [7, 0, 1], [7, 1, 1], [7, 2, 10], [7, 3, 1], [8, 0, 1], [8, 1, 1], [8, 2, 10], [8, 3, 1], [9, 0, 1], [9, 1, 1], [9, 2, 10], [9, 3, 1], [10, 0, 1], [10, 1, 1], [10, 2, 12], [10, 3, 1], [11, 0, 1], [11, 1, 1], [11, 2, 10], [11, 3, 1], [12, 0, 1], [12, 1, 1], [12, 2, 10], [12, 3, 1], [13, 0, 1], [13, 1, 1], [13, 2, 10], [13, 3, 1], [14, 0, 1], [14, 1, 1], [14, 2, 10], [14, 3, 1], [15, 0, 1], [15, 1, 1], [15, 2, 10], [15, 3, 1], [16, 0, 1], [16, 1, 1], [16, 2, 10], [16, 3, 1], [17, 0, 1], [17, 1, 1], [17, 2, 10], [17, 3, 1], [18, 0, 1], [18, 1, 1], [18, 2, 10], [18, 3, 1], [19, 0, 1], [19, 1, 1], [19, 2, 10], [19, 3, 1], [20, 0, 1], [20, 1, 1], [20, 2, 10], [20, 3, 1], [21, 0, 1], [21, 1, 1], [21, 2, 10], [21, 3, 1], [22, 0, 1], [22, 1, 1], [22, 2, 10], [22, 3, 1], [23, 0, 1], [23, 1, 1], [23, 2, 10], [23, 3, 1]]}
fig = go.Figure(data=go.Heatmap(x=[x[0] for x in maps['map1_ID']],
y=[x[1] for x in maps['map1_ID']],
z=[x[2] for x in maps['map1_ID']],
text=[x[2] for x in maps['map1_ID']],
texttemplate="%{text}",
textfont={"size":20},
hoverongaps = False,
colorscale=['lime','red','red']
)
)
fig.update_layout(height=300,
width=1000)