I recently found myself in the position of needing to plot polar, irregularly spaced data. I’ve done similar using regularly spaced values with no problem. However, I’ve found that when the points become greatly scattered, the triangulation does not translate from rectangular to polar very well. Below, find a code example that shows this; though it is much “better” than my real-world case that uses simulation results. Essentially, in the translation from regular to polar axes, many of the triangles overlap others, many features of the plot are lost, and the plot looks mangled in certain regions, esp. across the theta=0 boundary. While subtle here (but MUCH worse in the results I’m trying to visualize), some of the triangles lie outside of the triangulated region. It isn’t merely that the polar plot is suffering from poor data coverage; the triangulation is not working properly in polar coordinates and the results are quantitatively different than the rectangular plot.
The obvious work-around for this problem illustrates the issue more clearly. If we convert rad, theta back to x, y and do a rectangular plot, the triangulation is much better (not only is there no issue around theta=0, but there are no overlapping triangles), all of the details of the non-polar version are maintained, and the plot looks great. This is not the best solution, as polar plots in Matplotlib are quite elegant.
Any help here would be appreciated. It could be that triangulations are just not suited for polar plots; it could be that the theta=0 issue throws things off, etc; I’m just not sure. It would be perfect if I could use the polar axes in the end.
Demonstrate troubles with polar plots and triangulations.
import numpy as np
import matplotlib.pyplot as plt
angle=np.linspace(0, 2*np.pi, 20)
a1.tricontourf(x,y,z); a1.plot(x,y, ‘k+’)
a2.tricontourf(x,y,z); a2.plot(x,y, ‘k+’)
a3.tricontourf(x_ir,y_ir,z_ir); a3.plot(x_ir,y_ir, ‘k+’)
a4.tricontourf(x_ir,y_ir,z_ir); a4.plot(x_ir,y_ir, ‘k+’)
“Fix” back to rectangular.