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.

Different results with plotly ternary vs python-ternary

See original GitHub issue

Hello, Thank you so much for making this package! I’d like to overlay heatmap + scatter as mentioned in this issue: https://github.com/marcharper/python-ternary/issues/129 and addressed in https://github.com/marcharper/python-ternary/issues/121. However, I’m having trouble using the library.

I’m plotting median values of gene expression of a cell type across three species. When I use plotly, the result makes sense to me, where there are many dots in the middle, indicating many shared genes:

Screen Shot 2020-06-17 at 9 09 57 AM

However, when I use that same data for python-ternary, the result didn’t make any sense to me. There’s a bunch of points outside of the plot, and it’s not clear what’s happening to the rest. The code is in “Details” below.

Here is the code:

import ternary

def threewayplot(data, title=None):
    fig, tax = ternary.figure()
    tax.scatter(data.values.tolist())
    tax.set_title(title)
    tax.boundary(linewidth=1.0)
    
    corner_offset = 0.005
    tax.right_corner_label(data.columns[0], offset=corner_offset)
    tax.top_corner_label(data.columns[1], offset=0.12)
    tax.left_corner_label(data.columns[2], offset=corner_offset)
    tax.gridlines(color="blue", multiple=5)

    tax.ticks()

    tax.get_axes().axis('off')
    tax.clear_matplotlib_ticks()
    fig.tight_layout()
    
threewayplot(df_nonzero_for_ternary)

Screen Shot 2020-06-17 at 9 10 07 AM

I thought this was a simple rescaling issue and divided each column by the maximum so there were no values greater than 0, but this didn’t replicate the results I saw in Plotly, and don’t make sense to me as there are still dots outside of the plot, and the pattern doesn’t match what I see in plotly:

Screen Shot 2020-06-17 at 9 10 16 AM

threewayplot(df_nonzero_for_ternary/df_nonzero_for_ternary.max())

Do you know what may be happening?

Here is the data for reference: medians.csv.txt

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marcharpercommented, Jun 19, 2020

It could be useful to check that the sum isn’t equal to scale (and maybe that the values are all positive) warning the user if not. If you’d like to try to add it, feel free to open a PR! Maybe project_point is a good place to add the check, or a function in TernaryAxesSubplot that the other plotting functions can call when they receive data.

0reactions
ivan-marroquincommented, Oct 16, 2021

@marcharper

Indeed, there are so many ways to normalize data sets and it is up to users to decide what is the best way. However, I do think that it will be very helpful to let know new users of this nice package that the coordinates must sum to a constant (either 1 or 100, or even something else). Including the link to wikipedia will be an extra benefit!

And again, many thanks for such great package!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basics of Ternary plots with Python's Plotly | by Thiago Carvalho
Ternary plots are a less known solution that doesn't require our user to compare colors, circumference sizes, or 3D distances.
Read more >
Python Figure Reference: layout.ternary - Plotly
ternary. Code: fig.update_ternaries(...) Type: dict containing one or more of ... is determined by the sum minus the minimum values of the other...
Read more >
Ternary Plots in Plotly - GeeksforGeeks
A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like ......
Read more >
Ternary plot from plotly - python - Stack Overflow
I've never used this type of graph at all, but since the official reference drew a circle, I thought it would be possible...
Read more >
x lines of Python: Ternary diagrams - Agile Scientific
For the ternary plot itself I'm using the python-ternary library, ... (Theres one other option for Python, the ever-reliable plotly, ...
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