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

FF ternary_contour - add cliponaxis #3960

Closed
is95t opened this issue Nov 20, 2022 · 4 comments
Closed

FF ternary_contour - add cliponaxis #3960

is95t opened this issue Nov 20, 2022 · 4 comments

Comments

@is95t
Copy link

is95t commented Nov 20, 2022

Would it be possible to add the cliponaxis (as has been implemented for scatter ternary plots - see issue #1385 plotly/plotly.js#1385). This would allow the markers not to be cut off by the plot area when the showmarkers tag is set to true.
Currently I have a plot like so:

image

However, as he edge markers are cut off, it looks like I have less points. The plot below shows which points are plotted:

image

It would be really great to add this tag to the ff.ternary_contour plot, as it is so useful in the scatter ternary. If there is also a work around that I have missed, please let me know (I have had a go at this but can't find any way to get the markers not to be cut off).

Thanks

@alexcjohnson
Copy link
Collaborator

fig.update_traces(cliponaxis=False) after making the figure?

@is95t
Copy link
Author

is95t commented Nov 21, 2022

@alexcjohnson thanks for the suggestion, unfortunately this doesn't work (the code will run but the cliponaxis is not implemented). I believe this is to do with the fact the ternary_contour plot is part of the figure factory set and therefore might need to be implemented directly in the ff backend?

@alexcjohnson
Copy link
Collaborator

Ah, I see - looks like whatever we did to create those contour lines includes lines around the border that don't really add any value... and to compensate we clip them and add border lines. If we undo that, you can see the unclipped markers. Here's one of the examples from https://plotly.com/python/ternary-contour/ but taking that out and adding cliponaxis=False:

import plotly.figure_factory as ff
import numpy as np
Al, Cu = np.mgrid[0:1:7j, 0:1:7j]
Al, Cu = Al.ravel(), Cu.ravel()
mask = Al + Cu <= 1
Al, Cu = Al[mask], Cu[mask]
Y = 1 - Al - Cu

enthalpy = (Al - 0.5) * (Cu - 0.5) * (Y - 1)**2
fig = ff.create_ternary_contour(np.array([Al, Y, Cu]), enthalpy,
                                pole_labels=['Al', 'Y', 'Cu'],
                                ncontours=20,
                                coloring='lines',
                                showmarkers=True)
fig.update_traces(cliponaxis=False)
ax_override = dict(min=0, linewidth=0)  # the figure factory includes min=0.01, linewidth=2
fig.update_layout(ternary_aaxis=ax_override, ternary_baxis=ax_override, ternary_caxis=ax_override)

Screenshot 2022-11-21 at 14 05 24

I haven't looked into how hard it would be to remove those so this gives the exact behavior you want.

@is95t
Copy link
Author

is95t commented Nov 21, 2022

Ah that's good to know. I was using the line mode to see the points more clearly, however, filling the contours makes the lines on the edge less noticeable. I have then added a scatter over the top using your solution:

image

Here is the final output which looks great:

image

I think this is a workable solution, so I'm happy to close this. Thanks for the help and quick responses @alexcjohnson

@is95t is95t closed this as completed Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants