Question: I have problems when plotting a radial heatmap in Python. I would like to plot values from pandas dataframe that has column angle, distance and count. Values for angle are from -180 to 180. The distance are values from 0 to 20 and count tells the value count of that pair (angle, distance). Example of one dataframe whith df.head(10):  angle dist counts 0 -180.0 0.64 1 1 -180.0 0.67 1 2 -180.0 0.68 1 3 -180.0 0.72 1 4 -180.0 0.75 2 5 -180.0 0.76 2 6 -180.0 0.78 1 7 -180.0 0.79 4 8 -180.0 0.80 1 9 -180.0 0.82 2  I would like to discretize these values so that, for example, I have bins with a width of 5 degrees and a distance of 0.25. And in the cell, the count for those values is summarized and then plotted as a radial heatmap. For now I worked like this, I would define a pandas dataframe that imitates a matrix, whose columns are degrees from -180 to 180 (-180, -175, ..., 175, 180) and index values are from 0 to 20 with step of 0.25 (0, 0.25, ..., 19.75, 20) degree_bins = np.array([x for x in range(-180, 181, 5)]) distance_bins = np.array([x*0.25 for x in range(0, 81)]) round_bins = pd.DataFrame(0, index=distance_bins, columns=degree_bins)  And then i would sum count values: for row in tot.iterrows(): _, value = row degree = value["angle"] distance = value["distance"] count = value["counts"] degree_bin = np.digitize([degree], degree_bins)[0]-1 distance_bin = np.digitize([distance], distance_bins)[0]-1 round_bins.iloc[distance_bin, degree_bin] += count  I also found solution creating bins using groupby and unstack which is much faster than using for loop: counts = df.groupby(['distance_bins', 'angle_bins'])['counts'].sum().unstack()  But for now I just want to make ploting work correct. Code used for plotting: n = len(degree_bins) m = len(distance_bins) rad = np.linspace(0, 20.25, m) a = np.linspace(0, 2 * np.pi, n) r, th = np.meshgrid(rad, a) z = round_bins.to_numpy().T plt.figure(figsize=(20, 20)) plt.subplot(projection="polar") plt.pcolormesh(th, r, z, cmap='jet') plt.plot(a, r, ls='none', color='k') plt.grid() plt.colorbar()  This code gives me empty histogram. Any help would be appreciated.

Answer: You can use np.histogram2d to calculate the counts for each bin. It has a parameter weight= where you can put the given counts per entry. The heatmap can be directly plotted via ax.pcolormesh on a polar subplot. The angles need to be converted to radians to match the polar plot. Optionally you can use ax.set_theta_zero_location('N') to tell where the zero should go and/or ax.set_theta_direction('clockwise') to change the turning direction. import matplotlib.pyplot as plt import pandas as pd import numpy as np # first generate some dummy test data df = pd.DataFrame() df['angle'] = np.random.randint(-180, 181, 2000) df['dist'] = np.random.uniform(0, 20, len(df)) df['counts'] = np.random.randint(1, 5, len(df)) # define the bins degree_bins = np.arange(-180, 181, 5) distance_bins = np.arange(0, 20.001, 0.25) # calculate the 2D histogram hist, _, _ = np.histogram2d(df['angle'], df['dist'], bins=(degree_bins, distance_bins), weights=df['counts']) # plot the histogram as a polar heatmap plt.style.use('dark_background') # this makes the text and grid lines white fig, ax = plt.subplots(figsize=(10, 10), subplot_kw={'polar': True}) ax.grid(False) # pcolormesh gives an annoying warning when the grid is on ax.pcolormesh(np.radians(degree_bins), distance_bins, hist.T, cmap='hot') ax.grid(True) plt.tight_layout() plt.show()