Question

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: Polar filled contour without scatter

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:

Polar filled contour with scatter

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!

Was it helpful?

Solution

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)

enter image description here

I thought I could leave the question on anyways, it still can be helpful to other users.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top