I have some jagged contour plots that I need to smooth. I need to smooth them out without losing any of the contour lines. I have referred to these SO questions, but they don't quite offer a solution to my problem. Without any kind of filter, my plots look like this:
You can see that the outer contours are very jagged, and so are not presentation quality. If I run the data through a Gaussian filter of order 0 and sigma 2, (i.e., scipy.ndimage.gaussian_filter(z, 2)
), it smooths out the plots, but I lose the inner contours:
What is the best way to smooth the plot without losing the inner contours? The nature of the data I work with is that it always has the highest values near the center. Filtering spreads out the information and makes the inner contours disappear. These are the most important contours: the contours represent the risk for a loss of life, so generally the higher the value the more important it is.
I have considered two methods of smoothing the contour lines.
- Get each contour line coordinates via
contour_object.collections[col_index].get_paths()[path_index].vertices
and smooth / re-plot each one. This seems possible, but inelegant, and I'm not sure where to start on it. - Apply a Gaussian filter only on data greater than a certain value: e.g., 5*10-6. That is easy to do (loop through the array of data, and take from the original set if the value is greater than the cutoff, and the filtered set if it is not), but seems pretty arbitrary and difficult to justify.
I would like to do something like the first option, but it seems kind of like a hack. What is the best way to smooth out these contour plots?