Generate a polar heatmap on a semicircle from a csv file with three columns - python - matplotlib

Viewed 35

I have been trying to generate a heatmap plotted on a semicircle. The csv file I have has three columns. column 1 is Temperature, column 2 is angle and column 3 is occurrence.

Temperature phiangle Counts
25 0.71 4347
25 3.53 3149
25 4.94 2100
25 6.35 1731
25 7.76 1405
.... .... ....
249 172.94 3687
249 174.35 6592
249 175.76 12866
249 177.18 25725
249 180.00 23464

I have about 40K rows with temperature ranging from 25 to 249.

Now I would like the colorbar to show Counts (which is column 3). I would like the phiangle (column 2 which changes only from 0 to 180) on a semi circle. And temperature (column 1) to increase radially from the centre of the sphere.

Here is my code which does not work.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

scsv = pd.read_csv('polarchartdata.csv', sep=";")

x = scsv['Temperature'].values
y = scsv['phiangle'].values
yrad = np.radians(y)
z = scsv['Counts'].values

print(scsv)
print(x,y,z)  

fig, axes = plt.subplots(subplot_kw=dict(projection='polar'))
contourplot = axes.contourf(x, y, z)
axes.set_thetamin(0)
axes.set_thetamax(180)
plt.colorbar(contourplot, shrink=.6, pad=0.08)

plt.show()

I would want something similar with temperature going from the centre of the semicircle and outward.

[![enter image description here][1]][1]

Of course I would want to add a colorbar denoting the values in column 3.

When I Run this, I get a TypeError: Input z must be 2D, not 1D [1]: https://i.stack.imgur.com/EIM8v.png

0 Answers
Related