Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating contour plots #25

Closed
wants to merge 2 commits into from
Closed

Add support for creating contour plots #25

wants to merge 2 commits into from

Conversation

srstevenson
Copy link
Contributor

This commit adds a withContour method to CartesianPlot to add a contour plot to the plot. The name and colorscheme to be used may be specified as options. Usage is as follows:

val p = Plot()
  .withContour(x, y, z,
    ContourOptions()
      .name("a-contour-plot")
      .colorscale("Viridis"))

where x, y, and z are Iterables of equal length such that zₐ is the value to be plotted at coordinate (xₐ, yₐ).

This closes #12, and depends on #24.

@pbugnion
Copy link
Contributor

This looks really great. The internals are perfect -- I just had some thoughts regarding the interface.

At the moment, 3D plots offer an interface like:

val xs = Vector(-1.0, 0.0, 1.0)
val ys = Vector(0.0, 10.0)

val zs = Vector(
  Vector(1.0, 2.0, 1.0),
  Vector(5,0, 4.0, 5.0)
)

val p = ThreeDPlot().withSurface(xs, ys, zs)

i.e. the zs are an iterable of iterables, rather than a single long iterable. This is largely because Plotly doesn't support non-rectangular grids for 3D plots (AFAICT).

To maintain interface consistency, I think it would be useful to have a Plot.withContour(x, y, z) method where z is an iterable of iterables (note that the way the series is stored doesn't have to change -- only the Plot.withContour method). I think that we also want to keep list of triples interface, though, since it's more flexible than assuming a rectangular grid. We could do this either through an overloaded Plot.withContour(triples) method, where triples is an iterable of Tuple3, or with a new Plot.withContourFromTriples(triples) (maybe with a better name). I'm marginally more in favour of overloading, since we already use it a lot.

Either way, I think the type of the argument should be a single Iterable[(X, Y, Z)], rather than three iterables. This makes it clearer that we are referring to triples and also encodes the fact that the three arrays have to be of the same length in the type.

@pbugnion
Copy link
Contributor

This looks great!

This commit adds a `withContour` method to `Plot` to add a contour plot
to the plot. The name and colourscheme to be used may be specified as
options. Usage is as follows:

    val p = Plot().withContour(x, y, z, ContourOptions().colorscale("Jet"))

where x, y, and z are Iterables such that z_i is the value to be plotted
at coordinate (x_i, y_i).
This makes it clearer that we are referring to a triple of coordinates
(x, y, z), and ensures that the three series are of the same length.
@srstevenson
Copy link
Contributor Author

Realistically, I'm not going to come back to this. I encourage anyone interested to adopt it and finish it off.

@srstevenson srstevenson closed this Dec 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Contour plots
2 participants