Issue
I want to plot circles on a figure with a radius of each line, exactly like contour plots. so that i can put plt.clabel(inline=True), and I will get radius on each circle. Just like in figure2, I want to add labels to each radius in figure1 and that's not possible with plt.plot, so if anyone could please help me.
fig=plt.figure(figsize=[5,5],dpi=100)
t = np.linspace(0,2*np.pi)
plt.plot(0.01*np.cos(t),0.01*np.sin(t),lw=1, color='k')
plt.plot(25*np.cos(t),25*np.sin(t),lw=1, color='k')
plt.plot(50*np.cos(t),50*np.sin(t),lw=1, color='k')
plt.plot(75*np.cos(t),75*np.sin(t),lw=1, color='k')
plt.plot(100*np.cos(t),100*np.sin(t),lw=1, color='k')
plt.plot(125*np.cos(t),125*np.sin(t),lw=1, color='k')
Solution
If you want to exactly use plt.clabel
, a possible solution is to construct manually the entries for the contour plot like in the code below (the result is shown here). Probably this is not the more efficient way to do it but it should do the work at least for drawing circles. For a more elegant way you can refer to this answer https://stackoverflow.com/a/39402483/16243574.
fig, ax = plt.subplots(1, 2, figsize=[10,5],dpi=100)
t = np.linspace(0,2*np.pi)
ax[0].plot(0.01*np.cos(t),0.01*np.sin(t),lw=1, color='k')
ax[0].plot(25*np.cos(t),25*np.sin(t),lw=1, color='k')
ax[0].plot(50*np.cos(t),50*np.sin(t),lw=1, color='k')
ax[0].plot(75*np.cos(t),75*np.sin(t),lw=1, color='k')
ax[0].plot(100*np.cos(t),100*np.sin(t),lw=1, color='k')
ax[0].plot(125*np.cos(t),125*np.sin(t),lw=1, color='k')
coords = np.ones((len(t),len(t)))*t
Z = np.linspace(0, 130, len(t)*len(t))
Z = Z.reshape((len(t), len(t)))
rad = [0.1, 25, 50, 75, 100, 125]
spacing = [30, 60, 20, 15, 10, 5]
for i in range(len(rad)):
CS = ax[1].contour(rad[i]*np.cos(coords), rad[i]*np.sin(coords), Z, colors='k', levels=[rad[i]])
ax[1].clabel(CS, fontsize=10, inline=True, fmt='%.0f', inline_spacing=spacing[i])
Answered By - Luigi Favaro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.