-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
@EricThomson @clewis7 can I get your thoughts on this. The use case for this in 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 (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
) 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
) # 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) |
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() |
closes #191