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

Allow color to also be an iterable #25

Open
impredicative opened this issue Oct 3, 2023 · 4 comments
Open

Allow color to also be an iterable #25

impredicative opened this issue Oct 3, 2023 · 4 comments

Comments

@impredicative
Copy link

Currently, color has to be Optional[str]. I request that an iterable also be allowed for it, with the same length as x and y. This is intended to conveniently allow piecewise coloring. For example, I may want to sometimes specify color=['green', 'green', 'red', 'yellow'], etc.

@JeroenDelcour
Copy link
Owner

Interesting idea. I don't think I've ever had to make each point in a plot a different color (without also needing labels for each, at which point you need to make each point a separate plotting call anyway). What's your use case?

@impredicative
Copy link
Author

impredicative commented Oct 3, 2023

This is not my actual use case, but it's a simplified one: I am plotting the hourly weather temperature. If it's getting hotter, I want to use red. If it's getting colder, I want to use blue.

For now I would be okay with the label functionality remaining unchanged as Optional[str], applicable to the entire sequence.

@impredicative
Copy link
Author

Another use case is: I am plotting the hourly weather temperature. If however it's getting more humid, I use red. If it's getting less humid, I use green. If the humidity is the same, I use yellow. To restate, I am however plotting the temperature values.

@JeroenDelcour
Copy link
Owner

That sounds pretty unique. If more people express interest in such a convenience feature, I will look into it. For now, you should be able to make what you want by plotting each color as a separate call with something like this:

temperature = np.array([16, 17, 18, 16, 15, 18, 21, 19])
going_up_indices = [0,1,2,5,6]
going_down_indices = [3,4,7]
fig = tplot.Figure()
fig.scatter(x=going_up_indices, y=temperature[going_up_indices], color="red")
fig.scatter(x=going_down_indices, y=temperature[going_down_indices], color="blue")
fig.show()

Doing it for a line plot is similar: define the color for each line segment (two subsequent temperature values) and plot each segment separately in a for loop.

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