From nils106 at googlemail.com Wed Nov 6 06:41:55 2019 From: nils106 at googlemail.com (Nils Wagner) Date: Wed, 6 Nov 2019 12:41:55 +0100 Subject: [Matplotlib-users] Extract the x- and y-locations from the contour matrix C Message-ID: Hi All, in Octave you can do something like this % Define the input grid [x, y] = meshgrid(linspace(-2, 2)); % Calculate the two surfaces %z1 = y.^2 + 2*x; z1 = exp(-(x.^2 + y.^2)); %z2 = 2*y.^3 - x.^2; z2 = 0.4+0.0*x+0.0*y; % Visualize the two surfaces figure(1); surface(x, y, z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none'); surface(x, y, z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none'); view(3); camlight; axis vis3d % Take the difference between the two surface heights and find the contour % where that surface is zero. zdiff = z1 - z2; %C = contours(x, y, zdiff, [0 0]); figure(2); contour(x, y, zdiff, [0 0]); C = contour(x, y, zdiff, [0 0]); % Extract the x- and y-locations from the contour matrix C. xL = C(1, 2:end) yL = C(2, 2:end) % Interpolate on the first surface to find z-locations for the intersection % line. zL = interp2(x, y, z1, xL, yL); % Visualize the line. figure(3); line(xL, yL, zL, 'Color', 'k', 'LineWidth', 3); How can we extract the x- and y-locations from the contour matrix C in matplotlib? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jslavin at cfa.harvard.edu Wed Nov 6 15:13:43 2019 From: jslavin at cfa.harvard.edu (Slavin, Jonathan) Date: Wed, 6 Nov 2019 15:13:43 -0500 Subject: [Matplotlib-users] Extract the x- and y-locations from the contour matrix C In-Reply-To: References: Message-ID: Hi Nils, Extracting the x and y locations from a contour is a bit of a pain in matplotlib (or at least was last time I tried it). if you do something like c = ax.contour(x,y,z,...) (where ... stands in for the arguments you might want to supply) then c is a QuadContourSet. To get at the contour data you need to do something like p = c.collections[i].get_paths() (if you want the i'th collection, i.e. contour level number i, or you could iterate of c.collections) then p is a list of Path objects corresponding to each separate contour. p.vertices is then an N x 2 array of the x and y values An alternative to this is to use scikit-image package, in particular skimage.measure.find_contours. However in that case you do something like: c = find_contours(image,level) (where image is a 2D array) and you get back a list of (n,2) arrays with the indices of the image for the contour. To get the x,y values then you need to scale those indices accordingly. Jon > Date: Wed, 6 Nov 2019 12:41:55 +0100 > From: Nils Wagner > To: matplotlib-users at python.org > Subject: [Matplotlib-users] Extract the x- and y-locations from the > contour matrix C > Message-ID: > ChSWUBNBMDnZ-nCPQ at mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi All, > > in Octave you can do something like this > > % Define the input grid > [x, y] = meshgrid(linspace(-2, 2)); > % Calculate the two surfaces > %z1 = y.^2 + 2*x; > z1 = exp(-(x.^2 + y.^2)); > %z2 = 2*y.^3 - x.^2; > z2 = 0.4+0.0*x+0.0*y; > % Visualize the two surfaces > figure(1); > surface(x, y, z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none'); > surface(x, y, z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none'); > view(3); camlight; axis vis3d > % Take the difference between the two surface heights and find the contour > % where that surface is zero. > zdiff = z1 - z2; > %C = contours(x, y, zdiff, [0 0]); > figure(2); > contour(x, y, zdiff, [0 0]); > C = contour(x, y, zdiff, [0 0]); > % Extract the x- and y-locations from the contour matrix C. > xL = C(1, 2:end) > yL = C(2, 2:end) > % Interpolate on the first surface to find z-locations for the intersection > % line. > zL = interp2(x, y, z1, xL, yL); > % Visualize the line. > figure(3); > line(xL, yL, zL, 'Color', 'k', 'LineWidth', 3); > > How can we extract the x- and y-locations from the contour matrix C in > matplotlib? > -- Jonathan D. Slavin Astrophysicist - High Energy Astrophysics Division Center for Astrophysics | Harvard & Smithsonian Office: (617) 496-7981 | Cell: (781) 363-0035 60 Garden Street | MS 83 | Cambridge, MA 02138 -------------- next part -------------- An HTML attachment was scrubbed... URL: From story645 at gmail.com Tue Nov 26 16:27:00 2019 From: story645 at gmail.com (Hannah) Date: Tue, 26 Nov 2019 16:27:00 -0500 Subject: [Matplotlib-users] ANN: contrib_colormaps Message-ID: Want to make your own custom colormap? And share it with the world? Check out our new project: https://contrib_colormaps.pyviz.org/ [image: index] The project provides instructions for making custom colormaps that work with Matplotlib, colormaps that you can then contribute back to the project so that your colormaps can be widely available. You can also use the repository as a model for making your own colormaps: https://github.com/pyviz/contrib_colormaps -------------- next part -------------- An HTML attachment was scrubbed... URL: From nathan.goldbaum at gmail.com Tue Nov 26 16:46:07 2019 From: nathan.goldbaum at gmail.com (Nathan) Date: Tue, 26 Nov 2019 14:46:07 -0700 Subject: [Matplotlib-users] ANN: contrib_colormaps In-Reply-To: References: Message-ID: Hi Hannah, Cool! However, on firefox at least that site currently complains with the following SSL error: Websites prove their identity via certificates. Firefox does not trust this site because it uses a certificate that is not valid for contrib_colormaps.pyviz.org. The certificate is only valid for the following names: www.github.com, *.github.io, *.githubusercontent.com, *. github.com, github.com, github.io, githubusercontent.com Error code: SSL_ERROR_BAD_CERT_DOMAIN -Nathan On Tue, Nov 26, 2019 at 2:27 PM Hannah wrote: > Want to make your own custom colormap? And share it with the world? > > Check out our new project: https://contrib_colormaps.pyviz.org/ > [image: index] > > The project provides instructions for making custom colormaps that work > with Matplotlib, colormaps that you can then contribute back to the project > so that your colormaps can be widely available. You can also use the > repository as a model for making your own colormaps: > https://github.com/pyviz/contrib_colormaps > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users at python.org > https://mail.python.org/mailman/listinfo/matplotlib-users > -------------- next part -------------- An HTML attachment was scrubbed... URL: From story645 at gmail.com Tue Nov 26 17:50:44 2019 From: story645 at gmail.com (Hannah) Date: Tue, 26 Nov 2019 17:50:44 -0500 Subject: [Matplotlib-users] ANN: contrib_colormaps In-Reply-To: References: Message-ID: Thanks, wrote up the issue with credit to you ( https://github.com/pyviz/contrib_colormaps/issues/9#issue-529014368) cause I don't have access to the domain. On Tue, Nov 26, 2019, 4:46 PM Nathan wrote: > Hi Hannah, > > Cool! > > However, on firefox at least that site currently complains with the > following SSL error: > > Websites prove their identity via certificates. Firefox does not trust > this site because it uses a certificate that is not valid for > contrib_colormaps.pyviz.org. The certificate is only valid for the > following names: www.github.com, *.github.io, *.githubusercontent.com, *. > github.com, github.com, github.io, githubusercontent.com > > Error code: SSL_ERROR_BAD_CERT_DOMAIN > > -Nathan > > On Tue, Nov 26, 2019 at 2:27 PM Hannah wrote: > >> Want to make your own custom colormap? And share it with the world? >> >> Check out our new project: https://contrib_colormaps.pyviz.org/ >> [image: index] >> >> The project provides instructions for making custom colormaps that work >> with Matplotlib, colormaps that you can then contribute back to the project >> so that your colormaps can be widely available. You can also use the >> repository as a model for making your own colormaps: >> https://github.com/pyviz/contrib_colormaps >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users at python.org >> https://mail.python.org/mailman/listinfo/matplotlib-users >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: