'Positioning the axis label on polar plot / color coded legend

I'm trying to make the Distance label originate at the center of the plot and there to be a legend which describes the change in color based on the inputted change in temperature.

Here's the code:

import matplotlib.pyplot as plt
import numpy as np

theta = np.array(data["ra"])
dist_arr = np.array(data["dist"])
colors = np.log10(np.array(data["T"]))
area = np.array(data["M_V"])**2


fig = plt.figure(dpi=300)
ax = fig.add_subplot(projection='polar')
c = ax.scatter(theta, dist_arr,c=colors, s=area, cmap='hsv', alpha=0.75, label='Stars')
ax.set_title("Stars < 20 light years away", va='bottom')
ax.set_ylabel('Distance (ly)', size=12, loc='bottom')
ax.legend(loc='best', scatterpoints=1)

plt.show()

Here's the graph currently:

Polar Plot Output



Solution 1:[1]

Possible solution is the following:

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from math import pi

theta = np.array(data["ra"])
dist_arr = np.array(data["dist"])
colors = np.log10(np.array(data["T"]))
area = np.array(data["M_V"])**2

fig = plt.figure(figsize=(10,6), dpi=100)
ax = fig.add_subplot(projection='polar')

ax.set_theta_offset(pi/2)
ax.set_theta_direction(-1)
ax.set_rlabel_position(0)
plt.yticks([1,2,3,4,5,6,7,8,9,10], ['1','2','3','4','5','6','7','8','9','10'], color="grey", size=10)
plt.ylim(0,10)

c = ax.scatter(theta, dist_arr, c=colors, s=area, cmap='hsv', alpha=0.75, label='Stars')

# make colorbar
fig.colorbar(c, label="T")

ax.set_title("Stars < 20 light years away", va='bottom')
ax.set_ylabel('Distance (ly)', size=12, loc='bottom')

plt.show()

Returns

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gremur