Skip to content

colorbar_params in overlay_prediction_mask #410

@pcscp

Description

@pcscp
  • TIA Toolbox version: 1.2.0 (matplotlib 3.5.2)
  • Python version: 3.8.13
  • Operating System: Debian WSL2 on Windows 11 through visual code studio

Description

Reproduce the colorbar of the WSI inference plot of example notebook 6 (https://github.com/TissueImageAnalytics/tiatoolbox/blob/c773e1cd4d30d7b22e5d192fa2784b172d2b68a8/examples/06-semantic-segmentation.ipynb)

The color bar showed only 2 colors, mapped to the wrong class. I expected the same 5 colors mapped to the right class as seen in the example.

I am not sure if this is related to versions, my setup or that this is also happening to other people. My solution seems to do no harm by specifying explicitly the values. But I wanted to check that this is real or only happening to me before adding a fix.

What I Did

According to https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.colorbar.html the values property could (should?) be set with indexed colors.

In function overlay_prediction_mask, I added "values": uid_list

colorbar_params = {
"mappable": mpl.cm.ScalarMappable(cmap=cmap),
"boundaries": uid_list + [uid_list[-1] + 1],
"values": uid_list,
"ticks": [b + 0.5 for b in uid_list],
"spacing": "proportional",
"orientation": "vertical",
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions