qutip / qutip

QuTiP: Quantum Toolbox in Python
https://qutip.org
BSD 3-Clause "New" or "Revised" License
1.69k stars 635 forks source link

Add option to include colours to Bloch vectors instead of just cycling from a list #1292

Closed quantshah closed 4 years ago

quantshah commented 4 years ago

The Bloch sphere is an amazing tool for visualisations. In a project where I wanted to show the evolution of an initial quantum state to a final target, I wanted to put specific colours to the initial and final bloch vector.

Right now, the function [qutip.bloch.add_states](https://github.com/qutip/qutip/blob/master/qutip/bloch.py#L353) or [qutip.bloch.add_vectors](https://github.com/qutip/qutip/blob/master/qutip/bloch.py#L378) cycles through a fixed list of colours here - https://github.com/qutip/qutip/blob/master/qutip/bloch.py#L563

It would be nice if the user could also add an optional color argument or list of colours when adding a new vector such as bloch.add_vectors(vec, color="r") or bloch.add_vectors([vec1, vec2], color=["red", "green"])

In this case I would have liked to set the two colours in the vector myself.

image

rajathshetty20 commented 4 years ago

Hey, I tired solving this issue. I changed the add_vectors method such that it takes in an optional argument called 'color'. I created a dictionary called vector_color_specified which stores the vector-index and color as key-value pair. Then when plot_vectors is called, the color is taken from the dictionary if mentioned, otherwise the default value is used based on the cyclic color list which is already present. I tested my code and it works as you have mentioned above. So, is my approach right? Any advice would be helpful. This is the first open-source issue that I have taken up.

BoxiLi commented 4 years ago

Hi @rajathshetty20, Thanks for the interest. What you described sounds good. Would you like to make a Pull Request? You can go to the Pull Requests page and create one from a branch of your repository. There will be a template guiding you once you choose a branch.