-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Ternary contour plot #1413
Ternary contour plot #1413
Conversation
https://github.com/plotly/documentation/blob/source-design-merge/_posts/python/README.md
https://plot.ly/python/ternary-contour/ |
@nicolaskruchten can we please include some or all of these example datasets in |
|
||
# Annotations for ticklabels on side 0 | ||
annotations.extend([dict(showarrow=False, | ||
text=f'{ticklabel[j]}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we can't use f-strings in released code yet because we still support Python 2.7 and 3.5. (Note that we do use them in the code generation logic, but this isn't part of the released bundle).
This looks really cool @emmanuelle! I'll look through the code in more detail soon but the overall concept and structure look fine, so feel free to keep on working through your TODO list. ALso, as you make more examples, please add them as comments here in the PR so that folks can get a feel for how it works. Thanks! |
Thanks for the info and feedback @jackparmer and @jonmmease . I plan to finish working on my todo list tomorrow morning (Montréal time). |
This PR is ready for review! @jonmmease |
Great, thanks @emmanuelle. I'll do a thorough review this evening (EST), and then hopefully we can get this merge in tomorrow for 3.6.0. |
Awesome, thanks @jonmmease ! |
coloring=coloring, | ||
smoothing=smoothing) | ||
side_trace, tick_trace = _styling_traces_ternary(x_ticks, y_ticks) | ||
fig = go.FigureWidget(data=[contour_trace, tick_trace, side_trace], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently all of the other figure factories return a go.Figure
instance rather than a FigureWidget
. For consistency this should return a Figure
instance by default.
My eventual goal is for all of the figure factories to support an output_type
argument that can be set to 'dict'
, 'Figure'
, or 'FigureWidget'
to control how the figure is returned (See #1079). For this PR feel free to just always return a Figure
, or to add the output_type
argument that defaults to Figure
.
Hi @emmanuelle, I had one comment above about the return type, but otherwise your implementation looks great! I would like to take a step back, however, and discuss this general approach a bit. Here's my summary of how this works now (please correct me if I misstate something)
Here are a few hangups I have with this approach:
I'm not sure that it's practical, but I'd like to at least discuss an alternative approach. Could we do something like:
I think this would work fine for contours as lines, and I think we could probably even get the filled contour appearance by setting the With this approach, it would be possible for a user to use the figure factory to build the initial contour plot, but then they could then add their own What do you think @emmanuelle @jackparmer ? One additional thought is the question of whether we also want this figure factory to support computing the kernel density directly from a collection of input points in Barycentric coordinates. Something analagous to the |
Great suggestion, thank you @jonmmease. I'll definitely give it a try, it will have to wait tomorrow though... If you need this figure factory for the release and you're satisfied with the API, one solution is to merge this implementation and try another implementation later on. Regarding your other points, the input coordinates do not have to lie on a grid, they can be any set of points in barycentric coordinates (but the interpolation will be inside their convex hull only). |
Hi @emmanuelle, yeah I know this suggestion is a lot of change. Sorry I didn't process the approach enough when you first posted the WIP PR. I'm definitely open to merging this as is and revisiting it later. If my suggested approach works out, I think we should be able to keep the same figure factory API. @jackparmer what would you like to do? I think the near-term options are:
|
I think that merging (and releasing 3.6.0) as-is makes sense, then pursuing the approach that you outlined that does not use the cartesian plotly.js system (only barycentric). As you pointed out, it would be awesome if we could simulate smooth contours with many @empet , in the meantime, would you be interested in helping to see if Jon's approach (or something similar) is viable for ternary contours (see above)?
|
Yeah it would be best if we could use native ternary axes!
…On Wed, Jan 30, 2019 at 07:59 Emmanuelle Gouillart ***@***.***> wrote:
Great suggestion, thank you @jonmmease <https://github.com/jonmmease>.
I'll definitely give it a try, it will have to wait tomorrow though... If
you need this figure factory for the release and you're satisfied with the
API, one solution is to merge this implementation and try another
implementation later on.
Regarding your other points, the input coordinates do not have to lie on a
grid, they can be any set of points in barycentric coordinates (but the
interpolation will be inside their convex hull only).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1413 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMbA04cW5oguNdtp5_7iTLl4Q4uFUyLks5vIZcYgaJpZM4aU-J_>
.
|
My comments on @jonmmease raised questions:
|
@jonmmease, @jackparmer Second: We have 3 meshgrids x, y, z to get the contour lines, but skimage function uses only z-values. In the example at the link provided by @jonmmease, http://scikit-image.org/docs/dev/auto_examples/edges/plot_contours.html |
@empet we can still use the |
@jonmmease please tell me if I should still merge this PR, another one with the more native ternary scatter should be ready this afternoon. |
@emmanuelle I did it here https://plot.ly/~empet/15111, applying an isometric-log-ratio transformation to ternary points (that maps data isometrically on 2d-space), extracting contour lines via |
@empet awesome! How can I see the code generating this plot? My problem with plt.contour was that in a notebook it generated a matplotlib figure with the contour plot. |
@emmanuelle I'll upload the notebook on Plotly cloud in a few minutes and post here the link. Now I'm cleaning the code. |
@emmanuelle This is the link to the J. notebook https://plot.ly/~empet/15113 I learned about ilr - transformation from this paper: http://ima.udg.es/~jamf/Updating%20on%20the%20KDE%20for%20Compositional%20Data_MChM_definitive.pdf |
@emmanuelle The above method to plot the contour lines works only for proportions at the moment. |
@emmanuelle I was thinking of merging today, but I'm fine giving it another day or two since it sounds like you and @empet are making good progress! Why don't you open a new PR if you come up with an alternative approach, that way this one is still here as-is in case we decide to merge this now and update to a new approach later. Thanks! |
@emmanuelle I updated the notebook with a short presentation of the ilr-transform method. |
Thank you very much @empet ! |
so that we don't have to support them initially when we convert this figure factory to represent contours using scatterternary traces.
@emmanuelle, I wanted to make two more changes here before merging for 3.6.0
Does this look alright to you? |
@jonmmease yes it will be difficult to support |
Cool, definitely feel free to bring it back in #1418 🙂 |
This is a work in progress version of contour plots in ternary diagrams. I'm opening the PR even if it's too early to merge or do a thorough feedback, but I'd appreciate some quick feedback to know whether this is a good direction to go.
TODO
[x] Docstrings for helper functions.
[x] Improve coding style of helper functions in places.
[x] Decide whether other arguments (kw) need to be exposed in
create_ternaryplot
[x] Write more tests, in particular when errors are raised.
Other questions : where in the doc can I write a tutorial about this new function?