more cmap handling, add cmap_values#241
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