Skip to content

IHasColormap and automatic Colorbar tick placement (2)#1405

Merged
swharden merged 15 commits intomasterfrom
heatmap-ticks
Oct 24, 2021
Merged

IHasColormap and automatic Colorbar tick placement (2)#1405
swharden merged 15 commits intomasterfrom
heatmap-ticks

Conversation

@swharden
Copy link
Member

Hi @bclehmann, sorry again for messing-up the merge of #1403 before you were finished reviewing it 🙏😅

The comments you made in #1403 about the inequality tick labels have me a bit stuck... Can you clarify the intention for what setting the scale limits is supposed to do? I see it's only using a portion of the colormap to display the heatmap, but was the intent to do the opposite? (use the whole colormap to display a small range of heatmap values?) Maybe a use-case would help me get my head around this because I keep getting stuck on it.

I tried consulting old cookbooks and it looks like this behavior has been around for a long time... maybe limiting the scale just doesn't make sense if a colorbar is going to be shown? If this is the case I could just remove the colorbar from the cookbook recipes and call it a day.

For reference here's your original commit: bclehmann@c869c50#diff-458a1d86f745cd1b356fac59a162a25358ef2dd95789df1472b4af4bce5d7a50R178

Example

An alternative expectation of the behavior could be:
A. The heatmap would use the full color range stretched to display the value range 75 - 125
B. The colorbar min/max labels would be "≤75" and "≥125"

double[,] imageData = DataGen.SampleImageData();
var heatmap = plt.AddHeatmap(imageData);
heatmap.Update(imageData, min: 75, max: 125);
var cb = plt.AddColorbar(heatmap);

image

extends #1403 and resolves #1362

@bclehmann
Copy link
Member

I don't know if there's a reason we chose to clip the range instead of rescale it, and I think rescaling is probably a more useful (and more aesthetically pleasing) choice.

@swharden
Copy link
Member Author

swharden commented Oct 24, 2021

I don't know if there's a reason we chose to clip the range instead of rescale it

rescaling is probably a more useful

It probably made more sense earlier in the project before we had the new colorbar tools. Knowing what we know now, rescaling to use the full colorbar range seems like the least astonishing behavior. If we wanted to use a narrow range of the colormap I'm guessing we could add configuration for that in the Colormap class itself.

Either way, this plan sounds good! I'll put this work down today and give that a go tomorrow. This is the last issue I hope to resolve before pushing the next release to NuGet 🤞

Thanks again for all your input along the way! 🚀

Fixes problem where right-aligned multi-line strings appear left-justified
allows a portion of a colormap to be displayed in a colorbar
@swharden
Copy link
Member Author

Entertaining an alternative approach, we could keep the original heatmap behavior now that the colorbar has an option to restrict its display to a range of its colormap. What do you think of this strategy? If you like it, this may be ready to merge.

double[,] imageData = DataGen.SampleImageData();
var heatmap = plt.AddHeatmap(imageData);
heatmap.Update(imageData, min: 75, max: 125);

var cb = plt.AddColorbar(heatmap);

// configure the colorbar to only show a small range of the colormap
cb.MinColor = 75 / 255.0;
cb.MaxColor = 125 / 255.0;

// configure the colorbar to display inequality operators at the edges
cb.MaxIsClipped = true;
cb.MinIsClipped = true;

image

@bclehmann
Copy link
Member

Entertaining an alternative approach, we could keep the original heatmap behavior now that the colorbar has an option to restrict its display to a range of its colormap.

I think this is the best option if we clip intensities, but I still think that stretching is the best overall.

@swharden
Copy link
Member Author

swharden commented Oct 24, 2021

I think this is the best option if we clip intensities, but I still think that stretching is the best overall.

Sounds good! I'll work toward supporting that too 👍

Would you object to me removing the BackgroundImage? My thinking is that heatmaps support transparency and Plot.AddImage() could be used to display a bitmap beneath the heatmap. I'll extend AddImage() to better support offset/stretching (#1406).

The intent of these objects was probably to allow heatmaps to be displayed over specific coordinates.

CoordinatedHeatmap was created to fix the problem these fields were likely originally intended to solve.

Re-implementing this may allow these two plot types to be collapsed into one.
@bclehmann
Copy link
Member

Would you object to me removing the BackgroundImage? My thinking is that heatmaps support transparency and Plot.AddImage() could be used to display a bitmap beneath the heatmap. I'll extend AddImage() to better support offset/stretching (#1406).

I agree that there are better alternatives, but I would deprecate it rather than remove it to avoid breaking changes.

@swharden swharden merged commit fff2eac into master Oct 24, 2021
@swharden swharden deleted the heatmap-ticks branch October 24, 2021 22:28
@swharden
Copy link
Member Author

dang, I did it again 😅

I just picked this up after a few hours and didn't notice your response was <2 minutes old... hopefully you still approve 😬

I'll see if I can figure out how to make GitHub block merges if there are still open reviews

@swharden
Copy link
Member Author

I think the merging-too-early problem is fixed now. Sorry about that 😅

image

@bclehmann
Copy link
Member

dang, I did it again 😅

All good, I had nothing to add at the time. But now that I've come back I noticed this:
image

Link to workflow run: https://github.com/ScottPlot/ScottPlot/actions/runs/1378617487

I don't think it will cause any bugs because CoordinatedHeatmap has a completely isolated RenderHeatmap function, but it is probably worth fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Colorbar: improve automatic tick placement

2 participants