MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_color_logic

Function test_color_logic

lib/matplotlib/tests/test_collections.py:1173–1239  ·  view source on GitHub ↗
(pcfunc)

Source from the content-addressed store, hash-verified

1171
1172@mpl.style.context('default')
1173def test_color_logic(pcfunc):
1174 pcfunc = getattr(plt, pcfunc)
1175 z = np.arange(12).reshape(3, 4)
1176 # Explicitly set an edgecolor.
1177 pc = pcfunc(z, edgecolors='red', facecolors='none')
1178 pc.update_scalarmappable() # This is called in draw().
1179 # Define 2 reference "colors" here for multiple use.
1180 face_default = mcolors.to_rgba_array(pc._get_default_facecolor())
1181 mapped = pc.get_cmap()(pc.norm(z.ravel()))
1182 # GitHub issue #1302:
1183 assert mcolors.same_color(pc.get_edgecolor(), 'red')
1184 # Check setting attributes after initialization:
1185 pc = pcfunc(z)
1186 pc.set_facecolor('none')
1187 pc.set_edgecolor('red')
1188 pc.update_scalarmappable()
1189 assert mcolors.same_color(pc.get_facecolor(), 'none')
1190 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
1191 pc.set_alpha(0.5)
1192 pc.update_scalarmappable()
1193 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 0.5]])
1194 pc.set_alpha(None) # restore default alpha
1195 pc.update_scalarmappable()
1196 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
1197 # Reset edgecolor to default.
1198 pc.set_edgecolor(None)
1199 pc.update_scalarmappable()
1200 assert np.array_equal(pc.get_edgecolor(), mapped)
1201 pc.set_facecolor(None) # restore default for facecolor
1202 pc.update_scalarmappable()
1203 assert np.array_equal(pc.get_facecolor(), mapped)
1204 assert mcolors.same_color(pc.get_edgecolor(), 'none')
1205 # Turn off colormapping entirely:
1206 pc.set_array(None)
1207 pc.update_scalarmappable()
1208 assert mcolors.same_color(pc.get_edgecolor(), 'none')
1209 assert mcolors.same_color(pc.get_facecolor(), face_default) # not mapped
1210 # Turn it back on by restoring the array (must be 1D!):
1211 pc.set_array(z)
1212 pc.update_scalarmappable()
1213 assert np.array_equal(pc.get_facecolor(), mapped)
1214 assert mcolors.same_color(pc.get_edgecolor(), 'none')
1215 # Give color via tuple rather than string.
1216 pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=(0, 1, 0))
1217 pc.update_scalarmappable()
1218 assert np.array_equal(pc.get_facecolor(), mapped)
1219 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
1220 # Provide an RGB array; mapping overrides it.
1221 pc = pcfunc(z, edgecolors=(1, 0, 0), facecolors=np.ones((12, 3)))
1222 pc.update_scalarmappable()
1223 assert np.array_equal(pc.get_facecolor(), mapped)
1224 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
1225 # Turn off the mapping.
1226 pc.set_array(None)
1227 pc.update_scalarmappable()
1228 assert mcolors.same_color(pc.get_facecolor(), np.ones((12, 3)))
1229 assert mcolors.same_color(pc.get_edgecolor(), [[1, 0, 0, 1]])
1230 # And an RGBA array.

Callers

nothing calls this directly

Calls 11

pcfuncFunction · 0.85
update_scalarmappableMethod · 0.80
get_cmapMethod · 0.45
normMethod · 0.45
get_edgecolorMethod · 0.45
set_facecolorMethod · 0.45
set_edgecolorMethod · 0.45
get_facecolorMethod · 0.45
set_alphaMethod · 0.45
set_arrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…