Skip to content

Fix color ordering for single points in Bloch sphere. Fixes issue #2681#2754

Merged
Ericgig merged 4 commits into
qutip:masterfrom
QiLinXue:fix-bloch-color-ordering
Oct 24, 2025
Merged

Fix color ordering for single points in Bloch sphere. Fixes issue #2681#2754
Ericgig merged 4 commits into
qutip:masterfrom
QiLinXue:fix-bloch-color-ordering

Conversation

@QiLinXue

Copy link
Copy Markdown
Contributor

Description
When choosing the color for points to be plotted on a Bloch sphere, there are 2 options that are broken:

  1. By modifying Bloch.point_color directly. Note: code description seems to suggest this is deprecated, but the docs seem to suggest it is still supported.
  2. By passing a list of colours when calling Bloch.add_points.

In both of these cases, the order of points will get sorted by indperm, but the colours will not, leading to a mismatch.

For example,

from qutip import Bloch

x = [1, 0.5, 0, -0.5, -1]
y = [0, 0, 0, 0, 0]
z = [0, 0, 0, 0, 0]

b = Bloch()
b.add_points([x, y, z], colors=['red', 'orange', 'yellow', 'cyan', 'blue'])
b.show()

and

from qutip import Bloch

x = [1, 0.5, 0, -0.5, -1]
y = [0, 0, 0, 0, 0]
z = [0, 0, 0, 0, 0]

b = Bloch()
b.point_color=list(['red', 'orange', 'yellow', 'cyan', 'blue'])
b.add_points([
    x,
    y,
    z
])
b.show()

previously both did not work, and both cases are now fixed.

Related issues or PRs
Fixes #2681

@Ericgig Ericgig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix.

The towncrier file is a plain text file, no .rst in the name.

Would you be able to add a test for this? There are tests in qutip/tests/test_bloch.py, that you could use as a base to make one.

Comment thread qutip/tests/test_bloch.py Outdated

@Ericgig Ericgig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix

@Ericgig Ericgig merged commit f15c8f2 into qutip:master Oct 24, 2025
15 of 16 checks passed
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

Successfully merging this pull request may close these issues.

Color ordering for single points in a Bloch sphere

2 participants