Issue
I want the xy
axis to perfectly enclose the polar axis without the colorbar. So far I have:
import matplotlib.pyplot as plt
import numpy as np
# Random data
r = np.random.randn(1000)
theta = np.random.randn(1000)
fig = plt.figure()
axc = plt.subplot(236)
ax = plt.subplot(236, projection='polar')
ax.set(xticklabels=[], yticklabels=[])
ax.grid(False)
hist, phi_edges, r_edges = np.histogram2d(theta, r, bins=50)
axc.set_xlim(-r_edges[-1], r_edges[-1])
axc.set_ylim(-r_edges[-1], r_edges[-1])
X, Y = np.meshgrid(phi_edges, r_edges)
pc = ax.pcolormesh(X, Y, hist.T)
cbar = fig.colorbar(pc)
cbar.set_label("Counts", rotation=270, labelpad=15)
This produces a plot like:
I want the x
and y
axes to align with the polar plot (and the color bar outside the axes).
Does anybody have any suggestion?
Solution
You could try binding your color bar to both of the axes and setting its location to "right":
import matplotlib.pyplot as plt
import numpy as np
# Random data
r = np.random.randn(1000)
theta = np.random.randn(1000)
fig = plt.figure()
axc = plt.subplot(236)
ax = plt.subplot(236, projection='polar')
ax.set(xticklabels=[], yticklabels=[])
ax.grid(False)
hist, phi_edges, r_edges = np.histogram2d(theta, r, bins=50)
axc.set_xlim(-r_edges[-1], r_edges[-1])
axc.set_ylim(-r_edges[-1], r_edges[-1])
X, Y = np.meshgrid(phi_edges, r_edges)
pc = ax.pcolormesh(X, Y, hist.T)
cbar = plt.colorbar(pc, ax=[axc, ax], location='right')
cbar.set_label("Counts", rotation=270, labelpad=15)
plt.show()
The result:
Answered By - Ratislaus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.