question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a Figure.contour method

See original GitHub issue

Since MultiPolygons have landed, we should be able to support filled contours. Filled contours should be composed of multiple polygons each of which can have holes. Levels of contours should never overlap with each other - every new level that is contained within the bounds of a level should be a hole. This will make hover and tap tools great and makes sense conceptually if we think about elevation because no x, y has multiple elevations.

My original attempts at determining which polygons contain which others is contained in this notebook - but holoviews now has the concept of holes, so it should be more straightforward: https://anaconda.org/jsignell/contouring_with_holoviews/notebook

We can probably borrow most of the logic from holoviews if we want to depend on matplotlib. Otherwise there is a scikit-image method as well.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
ianthomas23commented, Mar 30, 2021

We have had quite a lot of contouring discussion over the last 6 months, spread over slack, discourse and github. Perhaps this is a good time and place to summarise the situation from my point of view.

I am the author of the Matplotlib contouring algorithm. I am working on a new project (https://github.com/contourpy/contourpy) to package up the original (2005) MPL C algorithm, the current (2014) C++ one and a new C++ one that I am working on that is both faster and uses less RAM than the current MPL one (if used sensibly). The idea is that Python projects will have access to contouring without having to have MPL as a dependency. My primary objective is to add contouring to Bokeh, but of course other Python projects will be welcome to use it and I expect MPL to adopt it.

This will be on the Python side of Bokeh. The Bokeh API is TBD, but I expect the contour lines at a particular level to be passed to bokehjs as a MultiLine, probably with some extra data to indicate the contour level. Similarly, filled contours between two levels would be passed to bokehjs as a MultiPolygon. The calculations stay on the Python side and the JavaScript side allows the usual interactivity of zooming, panning, selection, highlighting, etc.

Porting the algorithm to JavaScript might be an interesting project for someone, but I don’t expect it to run fast enough to be workable.

People often mention skimage’s find_contours and other similar “image contouring” algorithms, but they suffer from two problems:

  1. They only calculate line contours, not filled contours between two levels. The latter can be derived from the former of course, but you need to combine lines from both levels with parts or all of the boundary of the domain, and you have to determine the relationship between the outer/exterior polygons and their contained holes/interior polygons.
  2. They do not support missing data, e.g. via NumPy masked arrays. In geoscience (my background) we often have data that is ocean or land-specific with the other masked out. Contouring needs to take account of this properly.

The path of least resistance for Bokeh is to let me get contourpy to a state that I am happy with and deal with all the inconvenient packaging issues, then ensure the Bokeh API is sensible, and you will get contouring in a few months with very little effort required (other than by me!)

2reactions
bryevdvcommented, Jul 11, 2022

closed by #12020

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contour plot of matrix - MATLAB contour - MathWorks
contour ( Z ) creates a contour plot containing the isolines of matrix Z , where Z contains height values on the x-y...
Read more >
Drawing the Figure with Contour Lines - YouTube
Using contour lines to draw the figure is a great way to create a beautifully observed drawing. In this video I show you...
Read more >
Creating a map with contour lines - PyGMT
Figure.grdcontour method takes the grid input. It plots annotated contour lines, which are thicker and have the elevation/depth written on them, ...
Read more >
1.3.3.10. Contour Plot - Information Technology Laboratory
A contour plot is a graphical technique for representing a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format....
Read more >
How to Draw Contour Line Art: 4 Key Steps - PrepScholar Blog
Cross-contour lines are a way to add depth to your contour drawings without adding shading. To add them, you'll draw parallel lines that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found