I am attempting to generate a basic Splom graph, however, rather than having a standard color by row, I want to color individual cells. Thus, the coloring will be specific per subgraph of the Splom. I am doing this specifically to look at imputed values to ensure that the imputed data matches what is expected.
colors = pd.DataFrame(np.zeros(df.shape), columns = df.columns)
for val in missing_values:
colors.loc[val] = 1
fig = go.Figure()
fig.add_trace(
go.Splom(
dimensions = [
dict(label = column, values = df[column]) for column in df.columns
],
marker = dict(
color = colors
)
)
)
fig.update_layout(
title = "test"
)
offline.plot(fig)
This seems to kinda work, in that it shows most values where the color category is 0 (but not all). However, it does not show category 1 values at all and if there are too many category 1 values the splom does not show anything.
go.Splom has a special definition, different from any Plotly trace. Although it displays a subplot looking figure,
inspecting len(fig.data) we are noticing that it is 1, not n*n, where n is the number of dimensions (data variables). Hence you cannot map data from individual cells to designated colors.
Inspecting go.splom.Marker.color via
help(go.splom.Marker.color)` we learn that:
Help on property:
Sets the markercolor. It accepts either a specific color or an
array of numbers that are mapped to the colorscale relative to
the max and min values of the array or relative to
`marker.cmin` and `marker.cmax` if set.
The 'color' property is a color and may be specified as:
- A hex string (e.g. '#ff0000')
- An rgb/rgba string (e.g. 'rgb(255,0,0)')
- An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
- An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
- A named CSS color
- A number that will be interpreted as a color
according to splom.marker.colorscale
- A list or 1D array of any of the above
In your example, above, the definition of colors does not follow any of these cases. It is defined as a DataFrame whose shape len is >1. That’s why it cannot work as you expected.