Skip to content

FF ternary_contour - add cliponaxis #3960

Closed

Description

@is95t

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

Activity

  1. alexcjohnson commented on Nov 21, 2022

    @alexcjohnson
    Collaborator

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

  2. is95t commented on Nov 21, 2022

    @is95t
    Author

    @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?

  3. alexcjohnson commented on Nov 21, 2022

    @alexcjohnson
    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.

  4. is95t commented on Nov 21, 2022

    @is95t
    Author

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions