1

I am trying to plot arrows in a polar plot in matplotlib. I shall have 2 sets, one set points towards the center of the plot, I can get it easily; one set should tangent to the circle of radius r at the point considered. Both length should be a function of the angle theta.

I can get there by some cumbersome trigonometric consideration for the second set, but I was wondering if there would be a more elegant (and readable) way to do so. Especially as this is for a demo for students.

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
matplotlib.rcParams['figure.figsize'] = (8,8)
theta=np.linspace(0,2*np.pi,13)
rayon=np.linspace(R,R,13)
ax = plt.subplot(111, projection='polar')
ax.plot(theta, rayon,'.',markersize=10)
ax.set_rmax(0.6)
plt.arrow(theta[1], 0.5, 0, -0.25,  width = 0.015, edgecolor = 'red',  lw = 3,head_width=0.1, head_length=0.05)
l=.5
plt.arrow(theta[1], 0.5, np.arctan(l/.5), (np.sqrt(.5**2+l**2)-.5),  width = 0.015,
             edgecolor = 'green',  lw = 3,head_width=0.1, head_length=0.05)

plt.show()

This is what I get as a plot

Thomas Kühn
  • 8,046
  • 3
  • 33
  • 52
  • I think it might be cleanest to write two simple conversion functions like in [this answer](https://stackoverflow.com/a/26757297/2454357) to get the calculations out of the `arrow` command. I don't think you can get around doing the actual math. – Thomas Kühn Sep 25 '18 at 06:14
  • If you are bothered by the arrow head not being straight, have a look at the bottom of [this documentation page](https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.arrow.html). They recommend to use `ax.annotate` instead of `arrow` for polar plots. – Thomas Kühn Sep 25 '18 at 06:19

0 Answers0