Skip to content

Commit fe749ce

Browse files
committed
uniform colors WIP
1 parent 7974436 commit fe749ce

File tree

16 files changed

+118
-63
lines changed

16 files changed

+118
-63
lines changed

examples/gridplot/multigraphic_gridplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def make_circle(center, radius: float, n_points: int = 75) -> np.ndarray:
106106
gaussian_cloud2 = np.random.multivariate_normal(mean, covariance, n_points)
107107

108108
# add the scatter graphics to the figure
109-
figure["scatter"].add_scatter(data=gaussian_cloud, sizes=2, cmap="jet")
109+
figure["scatter"].add_scatter(data=gaussian_cloud, sizes=2, cmap="jet", uniform_color=False)
110110
figure["scatter"].add_scatter(data=gaussian_cloud2, colors="r", sizes=2)
111111

112112
figure.show()

examples/line/line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
sine = figure[0, 0].add_line(data=sine_data, thickness=5, colors="magenta")
3131

3232
# you can also use colormaps for lines!
33-
cosine = figure[0, 0].add_line(data=cosine_data, thickness=12, cmap="autumn")
33+
cosine = figure[0, 0].add_line(data=cosine_data, thickness=12, cmap="autumn", uniform_color=False)
3434

3535
# or a list of colors for each datapoint
3636
colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25
37-
sinc = figure[0, 0].add_line(data=sinc_data, thickness=5, colors=colors)
37+
sinc = figure[0, 0].add_line(data=sinc_data, thickness=5, colors=colors, uniform_color=False)
3838

3939
figure[0, 0].axes.grids.xy.visible = True
4040
figure.show()

examples/line/line_cmap.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
data=sine_data,
2828
thickness=10,
2929
cmap="plasma",
30-
cmap_transform=sine_data[:, 1]
30+
cmap_transform=sine_data[:, 1],
31+
uniform_color=False,
3132
)
3233

3334
# qualitative colormaps, useful for cluster labels or other types of categorical labels
@@ -36,7 +37,8 @@
3637
data=cosine_data,
3738
thickness=10,
3839
cmap="tab10",
39-
cmap_transform=labels
40+
cmap_transform=labels,
41+
uniform_color=False,
4042
)
4143

4244
figure.show()

examples/line/line_cmap_more.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,43 @@
2626
line0 = figure[0, 0].add_line(sine, thickness=10)
2727

2828
# set colormap along line datapoints, use an offset to place it above the previous line
29-
line1 = figure[0, 0].add_line(sine, thickness=10, cmap="jet", offset=(0, 2, 0))
29+
line1 = figure[0, 0].add_line(sine, thickness=10, cmap="jet", uniform_color=False, offset=(0, 2, 0))
3030

3131
# set colormap by mapping data using a transform
3232
# here we map the color using the y-values of the sine data
3333
# i.e., the color is a function of sine(x)
34-
line2 = figure[0, 0].add_line(sine, thickness=10, cmap="jet", cmap_transform=sine[:, 1], offset=(0, 4, 0))
34+
line2 = figure[0, 0].add_line(
35+
sine,
36+
thickness=10,
37+
cmap="jet",
38+
cmap_transform=sine[:, 1],
39+
uniform_color=False,
40+
offset=(0, 4, 0),
41+
)
3542

3643
# make a line and change the cmap afterward, here we are using the cosine instead fot the transform
37-
line3 = figure[0, 0].add_line(sine, thickness=10, cmap="jet", cmap_transform=cosine[:, 1], offset=(0, 6, 0))
44+
line3 = figure[0, 0].add_line(
45+
sine,
46+
thickness=10,
47+
cmap="jet",
48+
cmap_transform=cosine[:, 1],
49+
uniform_color=False,
50+
offset=(0, 6, 0)
51+
)
52+
3853
# change the cmap
3954
line3.cmap = "bwr"
4055

4156
# use quantitative colormaps with categorical cmap_transforms
4257
labels = [0] * 25 + [1] * 5 + [2] * 50 + [3] * 20
43-
line4 = figure[0, 0].add_line(sine, thickness=10, cmap="tab10", cmap_transform=labels, offset=(0, 8, 0))
58+
line4 = figure[0, 0].add_line(
59+
sine,
60+
thickness=10,
61+
cmap="tab10",
62+
cmap_transform=labels,
63+
uniform_color=False,
64+
offset=(0, 8, 0),
65+
)
4466

4567
# some text labels
4668
for i in range(5):

examples/line/line_colorslice.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
sine = figure[0, 0].add_line(
3131
data=sine_data,
3232
thickness=5,
33-
colors="magenta"
33+
colors="magenta",
34+
uniform_color=False, # initialize with same color across vertices, but we will change the per-vertex colors later
3435
)
3536

3637
# you can also use colormaps for lines!
3738
cosine = figure[0, 0].add_line(
3839
data=cosine_data,
3940
thickness=12,
4041
cmap="autumn",
42+
uniform_color=False,
4143
offset=(0, 3, 0) # places the graphic at a y-axis offset of 3, offsets don't affect data
4244
)
4345

@@ -47,6 +49,7 @@
4749
data=sinc_data,
4850
thickness=5,
4951
colors=colors,
52+
uniform_color=False,
5053
offset=(0, 6, 0)
5154
)
5255

@@ -56,6 +59,7 @@
5659
data=zeros_data,
5760
thickness=8,
5861
colors="w",
62+
uniform_color=False, # initialize with same color across vertices, but we will change the per-vertex colors later
5963
offset=(0, 10, 0)
6064
)
6165

examples/line/line_dataslice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
sine = figure[0, 0].add_line(data=sine_data, thickness=5, colors="magenta")
3131

3232
# you can also use colormaps for lines!
33-
cosine = figure[0, 0].add_line(data=cosine_data, thickness=12, cmap="autumn")
33+
cosine = figure[0, 0].add_line(data=cosine_data, thickness=12, cmap="autumn", uniform_color=False)
3434

3535
# or a list of colors for each datapoint
3636
colors = ["r"] * 25 + ["purple"] * 25 + ["y"] * 25 + ["b"] * 25
37-
sinc = figure[0, 0].add_line(data=sinc_data, thickness=5, colors=colors)
37+
sinc = figure[0, 0].add_line(data=sinc_data, thickness=5, colors=colors, uniform_color=False)
3838

3939
figure.show()
4040

examples/line_collection/line_collection_slicing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
multi_data,
2727
thickness=[2, 10, 2, 5, 5, 5, 8, 8, 8, 9, 3, 3, 3, 4, 4],
2828
separation=4,
29+
uniform_color=False,
2930
metadatas=list(range(15)), # some metadata
3031
names=list("abcdefghijklmno"), # unique name for each line
3132
)

examples/scatter/scatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points
3737

3838
# use an alpha value since this will be a lot of points
39-
figure[0, 0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6)
39+
figure[0, 0].add_scatter(data=cloud, sizes=3, colors=colors, uniform_color=False, alpha=0.6)
4040

4141
figure.show()
4242

examples/scatter/scatter_cmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
colors = ["yellow"] * n_points + ["cyan"] * n_points + ["magenta"] * n_points
3737

3838
# use an alpha value since this will be a lot of points
39-
figure[0, 0].add_scatter(data=cloud, sizes=3, colors=colors, alpha=0.6)
39+
figure[0, 0].add_scatter(data=cloud, sizes=3, colors=colors, uniform_color=False, alpha=0.6)
4040

4141
figure.show()
4242

fastplotlib/graphics/_positions_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(
7171
self,
7272
data: Any,
7373
colors: str | np.ndarray | tuple[float] | list[float] | list[str] = "w",
74-
uniform_color: bool = False,
74+
uniform_color: bool = True,
7575
cmap: str | VertexCmap = None,
7676
cmap_transform: np.ndarray = None,
7777
size_space: str = "screen",
@@ -89,7 +89,7 @@ def __init__(
8989
if cmap is not None:
9090
# if a cmap is specified it overrides colors argument
9191
if uniform_color:
92-
raise TypeError("Cannot use cmap if uniform_color=True")
92+
raise TypeError("Cannot use `cmap` if `uniform_color=True`, pass `uniform_color=False` to use `cmap`.")
9393

9494
if isinstance(cmap, str):
9595
# make colors from cmap
@@ -127,7 +127,7 @@ def __init__(
127127
if not isinstance(colors, str): # not a single color
128128
if not len(colors) in [3, 4]: # not an RGB(A) array
129129
raise TypeError(
130-
"must pass a single color if using `uniform_colors=True`"
130+
"Must pass `uniform_colors=False` if using multiple colors"
131131
)
132132
self._colors = UniformColor(colors)
133133
self._cmap = None

0 commit comments

Comments
 (0)