问题
Thanks to this very helpful post, I finally figured out how to make a polar filled-contour plot. However, when I moved to the next step and tried to add a scatter point to the same plot, I ran in some problems. Here is the original script:
import numpy as np
import matplotlib.pyplot as plt
#-- Generate Data -----------------------------------------
# Using linspace so that the endpoint of 360 is included...
azimuths = np.radians(np.linspace(0, 360, 20))
zeniths = np.arange(0, 70, 10)
r, theta = np.meshgrid(zeniths, azimuths)
values = np.random.random((azimuths.size, zeniths.size))
#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
plt.show()
Which produced this image:
If I add also a scatter plot:
#-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
ax.scatter(np.radians(140), 40, s=20, c='White')
I get instead this image:
Why do I get the thick white border between the filled contours and the axes? How do I get rid of it?
Thank you very much!
回答1:
Ops, sorry the answer occurred to me two minutes after a asked my question. I just realized that adding a scatter plot somehow changes the axes limits. Forcing the axes to the desired interval fixes the problem.
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta, r, values)
ax.scatter([np.radians(140)], [40], s=20, c='White')
ax.set_rmax(60)
ax.set_rmin(0)
I thought I could leave the question on anyways, it still can be helpful to other users.
来源:https://stackoverflow.com/questions/22360421/overlapping-polar-countourf-and-scatter-plot