contour
Hide contour linestroke on pyplot.contourf to get only fills
I finally found a proper solution to this long-standing problem (currently in Matplotlib 3), which does not require multiple calls to contour or rasterizing the figure. Note that the problem illustrated in the question appears only in saved publication-quality figures formats like PDF, not in lower-quality raster files like PNG. My solution was inspired by … Read more
How to crop the internal area of a contour?
It is unclear in your question whether you want to actually crop out the information that is defined within the contour or mask out the information that isn’t relevant to the contour chosen. I’ll explore what to do in both situations. Masking out the information Assuming you ran cv2.findContours on your image, you will have … Read more
OpenCV – visualize polygonal curve(s) extracted with cv2.approxPolyDP()
The problem is in visualization only: drawContours expects array (list in case of python) of contours, not just one numpy array (which is returned from approxPolyDP). Solution is the following: replacing cv2.drawContours(canvas, approx, -1, (0, 0, 255), 3) to cv2.drawContours(canvas, [approx], -1, (0, 0, 255), 3)
Python : 2d contour plot from 3 lists : x, y and rho?
You need to interpolate your rho values. There’s no one way to do this, and the “best” method depends entirely on the a-priori information you should be incorporating into the interpolation. Before I go into a rant on “black-box” interpolation methods, though, a radial basis function (e.g. a “thin-plate-spline” is a particular type of radial … Read more
What is the algorithm that opencv uses for finding contours?
If you read the documentation it is mentioned this function implements the algorithm of: Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by Border Following. CVGIP 30 1, pp 32-46 (1985) OpenCV is open source if you want to see how this is implemented just need to read the code: https://github.com/opencv/opencv/blob/master/modules/imgproc/src/contours.cpp#L1655 … Read more
How do you create a legend for a contour plot?
You could also do it directly with the lines of the contour, without using proxy artists. import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt matplotlib.rcParams[‘xtick.direction’] = ‘out’ matplotlib.rcParams[‘ytick.direction’] = ‘out’ delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y … Read more
Python/Matplotlib – Colorbar Range and Display Values
If I understand correctly what you want, I think this should do it: import numpy as np import matplotlib.pyplot as plt xi = np.array([0., 0.5, 1.0]) yi = np.array([0., 0.5, 1.0]) zi = np.array([[0., 1.0, 2.0], [0., 1.0, 2.0], [-0.1, 1.0, 2.0]]) v = np.linspace(-.1, 2.0, 15, endpoint=True) plt.contour(xi, yi, zi, v, linewidths=0.5, colors=”k”) plt.contourf(xi, … Read more