Issue
I have a list/array(?) in this format
data = [[1,1,2],[4,3,3,8,1],[2,3,4]]
(The real list is much longer with more days and temperatures)
How do I get x and y needed for this function?
plt.hist2d(x, y)
Background:
I would like to make a time series heatmap like here: How to plot Time Series Heatmap with Python? , where x axis is days, y axis is temperature and hue is the frequency of a specific temperature in that day
Update
Seems like I got it to work by modifying @Guldborg92 's answer
x = []
y = []
for day in range(0, len(data)):
for temperature in data[day]:
x.append(day)
y.append(temperature)
plt.hist2d(x, y)
Solution
This is a more pythonic version using comprehensions instead of loops:
x = [day for day, temps in enumerate(data) for _ in temps]
y = [temp for day in data for temp in day]
plt.hist2d(x, y, bins=[15, 30], cmap='OrRd')
Answered By - tdy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.