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

TernaryAxesSubplot.scatter() skips first default color in version 1.0.8 #194

Open
DrGFreeman opened this issue Jul 12, 2022 · 1 comment

Comments

@DrGFreeman
Copy link

DrGFreeman commented Jul 12, 2022

Description

The TernaryAxesSubplot.scatter() method skips the first color of the default matplotlib colormap in version 1.0.8.

Steps to reproduce

import ternary

fig, tax = ternary.figure(scale=1)
tax.scatter([(1.1/3, 0.9/3, 1/3)], label="first")
tax.scatter([(0.9/3, 1.1/3, 1/3)], label="second")
tax.legend()
tax.set_title(f"python-ternary {ternary.__version__}")
tax.show()

Expect behavior

The default matplotlib colors are used starting with blue, followed by orange, etc. This is the behavior with version 1.0.7:

image

Actual behavior

The first scatter plot uses the second default matplotlib color (orange), followed by the third (green), etc.:

image

Notes

Matplotlib version used in both cases above: 3.5.2

@DrGFreeman DrGFreeman changed the title ternary.scatter() skips first default color in version 1.0.8 TernaryAxesSubplot.scatter() skips first default color in version 1.0.8 Jul 12, 2022
@bmondal94
Copy link

bmondal94 commented Jul 15, 2022

Answer: The first color is missing in version 1.0.8 because of the addition of one additional function call in TernaryAxesSubplot class, ( Add functions for setting a ternary specific background color ). It calls self.set_background_color(), which intern calls background_color() from heatmapping.py (Please check out the __init__ in TernaryAxesSubplot). This background_color() function essentially creates the triangular region filled with 'whitesmoke' color, which you see in the background of your 2nd figure.
Now, let's go back to your code.

fig, tax = ternary.figure(scale=1) 
tax.scatter([(1.1/3, 0.9/3, 1/3)], label="first")
tax.scatter([(0.9/3, 1.1/3, 1/3)], label="second")
tax.legend()
tax.set_title(f"python-ternary {ternary.__version__}")
tax.show()

Apparently, it looks like you created the tax in line 1 and drew scatter after that. So, the first scatter call should be the first time something is drawn on your axis. But note, the ternary.figure() already called the background_color() function. So, you already drew the first drawing on your axis, and the tax.scatter() call is actually the 2nd time you are drawing something on the axis. That's why the 1st color is missing in tax.scatter().
You can easily check this if you comment out the self.set_background_color() call in __init__ in TernaryAxesSubplot class.

Solution: You just have to restart your color cycle.

import ternary
import matplotlib.pyplot as plt

fig, tax = ternary.figure(scale=1)
plt.gca().set_prop_cycle(None)  # restarts the color cycle
tax.scatter([(1.1/3, 0.9/3, 1/3)], label="first")
tax.scatter([(0.9/3, 1.1/3, 1/3)], label="second")
tax.legend()
tax.set_title(f"python-ternary {ternary.__version__}")
tax.show()

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