Thanks to visit codestin.com
Credit goes to github.com

Skip to content

more cmap handling, add cmap_values #241

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

Merged
merged 16 commits into from
Jun 21, 2023
Merged

more cmap handling, add cmap_values #241

merged 16 commits into from
Jun 21, 2023

Conversation

kushalkolar
Copy link
Member

closes #191

@kushalkolar
Copy link
Member Author

kushalkolar commented Jun 17, 2023

@EricThomson @clewis7 can I get your thoughts on this.

The use case for this in LineCollection is to make it really easy to color contours using a cmap based on the various quality metrics! For example let's say you used the "jet" cmap and wanted to visualize the cnn classifier predictions, things which are probably neurons would have red contours, and low classified things would be blue.

It also allows for using qualitative colormaps and giving it arrays of ints, like cluster labels. So you could see the spatial distribution of different clusters for example.

So far, for LineCollection the cmap and cmap_values can also be changed after it's created (this is necessary for looking at different quality metrics of contours).

(meanwhile in matplotlib, it's really hard 🙃 https://stackoverflow.com/questions/8500700/how-to-plot-a-gradient-color-line)

usage is really simple:

# cmap_values from an array, so the colors on the sine line will be based on the sine y-values
sine_graphic = plot.add_line(
    data=sine, 
    thickness=10, 
    cmap="plasma", 
    cmap_values=sine[:, 1]
)

# qualitative colormaps, useful for cluster labels for example
cmap_values = [0] * 25 + [5] * 25 + [1] * 25 + [2] * 25
cosine_graphic = plot.add_line(
    data=cosine, 
    thickness=10, 
    cmap="tab10", 
    cmap_values=cmap_values
)

image

For collections:

# this makes 16 circles, so we can create 16 cmap values, so it will use these values to set the
# color of the line based by using the cmap as a LUT with the corresponding cmap_value

# highest values, lowest values, mid-high values, mid values
cmap_values = [10] * 4 + [0] * 4 + [7] * 4 + [5] * 4

plot.add_line_collection(
    circles, 
    cmap="bwr", 
    cmap_values=cmap_values, 
    thickness=10
)

image

# this makes 16 circles, so we can create 16 cmap values, so it will use these values to set the
# color of the line based by using the cmap as a LUT with the corresponding cmap_value

# qualitative colormap used for mapping 16 cmap values for each line
# for example, these could be cluster labels
cmap_values = [
    0, 1, 1, 2,
    0, 0, 1, 1,
    2, 2, 3, 3,
    1, 1, 1, 5
]

plot = fpl.Plot()

plot.add_line_collection(
    circles, 
    cmap="tab10", 
    cmap_values=cmap_values, 
    thickness=10
)

plot.show()

plot.canvas.set_logical_size(800, 800)

image

@kushalkolar kushalkolar mentioned this pull request Jun 17, 2023
8 tasks
@kushalkolar
Copy link
Member Author

update scatter to use this as well

from fastplotlib import Plot, run
import numpy as np
from pathlib import Path
from sklearn.cluster import AgglomerativeClustering


plot = Plot()

data_path = Path(__file__).parent.parent.joinpath("data", "iris.npy")
data = np.load(data_path)


agg = AgglomerativeClustering(n_clusters=3)

agg.fit_predict(data)


scatter_graphic = plot.add_scatter(
    data=data[:, :-1],
    sizes=15,
    alpha=0.7,
    cmap="Set1",
    cmap_values=agg.labels_
)

plot.show()

plot.canvas.set_logical_size(800, 800)

plot.auto_scale()

scatter_graphic.cmap = "tab10"

if __name__ == "__main__":
    run()

scatter_cmap

@kushalkolar kushalkolar changed the title more cmap handling more cmap handling, add cmap_values Jun 21, 2023
@kushalkolar kushalkolar merged commit ec899f3 into master Jun 21, 2023
@kushalkolar kushalkolar deleted the cmap-values branch June 22, 2023 07:52
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.

More ColorsFeature handling
1 participant