Skip to content

Beginnings of heatmaps#424

Merged
swharden merged 137 commits intoScottPlot:masterfrom
bclehmann:heatmap-continuous
Jun 1, 2020
Merged

Beginnings of heatmaps#424
swharden merged 137 commits intoScottPlot:masterfrom
bclehmann:heatmap-continuous

Conversation

@bclehmann
Copy link
Member

Purpose:
New heatmap plottable

New functionality (code):
Provide a code example demonstrating new functionality achieved with this pull request (if applicable)

int[] xs = Enumerable.Range(0, 100).ToArray();
int[] ys = Enumerable.Range(0, 100).ToArray();
double[][] intensities = new double[ys.Length][];

for (int i = 0; i < ys.Length; i++) {
	intensities[i] = new double[xs.Length];
	for (int j = 0; j < xs.Length; j++) {
		intensities[i][j] = Math.Sqrt(Math.Pow(xs[j] - 50, 2) + Math.Pow(ys[i] - 50, 2));
	}
}

plt.PlotHeatmap(intensities);

New functionality (image):
image

Currently the only supported colourmap is grayscale, and the scale is worthless. I was going to continue working on it but I've got some stuff to take care of. I should be back to finish it up, but I thought I'd open the PR now in case you want to have a crack at it.

@bclehmann
Copy link
Member Author

#420 (Nice)

@bclehmann bclehmann force-pushed the heatmap-continuous branch from c3bf074 to e416504 Compare May 23, 2020 17:59
@bclehmann
Copy link
Member Author

I rebased, so theoretically we should have all the .editorconfig goodness

@bclehmann
Copy link
Member Author

image

I think it looks pretty good? I think after I add a couple more colourmaps the only thing left to do is sort out axes

@bclehmann
Copy link
Member Author

@swharden We now have six colourmaps (although grayscale/grayscale inverted perhaps counts as only one). I haven't looked at any of matplotlibs other colourmaps but some of them may be under a friendly license. I would be a tad interested in adding some (in)famous ones like jet, but I'm again not sure about the licensing.

On the repo you linked you have two colourmaps I don't recognize: https://github.com/swharden/Spectrogram/blob/master/src/Spectrogram/Colormaps/VdBlues.cs
and https://github.com/swharden/Spectrogram/blob/master/src/Spectrogram/Colormaps/VdGreens.cs

Are these your own? Or are they under a generous license? I know you said adding heatmaps to this library would make your spectogram simpler.

@swharden
Copy link
Member

swharden commented May 24, 2020

@Benny121221 this is looking so good!

I rebased, so theoretically we should have all the .editorconfig goodness

Does Ctrl+K, Ctrl+D autoformat the document for you?

Google's Turbo is under Apache 2.0 (discussed in #420, nice)

I'm not a lawyer, but since we are distributing a derivative work (not the unmodified original work) it looks like it's okay to include in a MIT project: https://en.wikipedia.org/wiki/Apache_License#Licensing_conditions

This matplotlib discussion matplotlib/matplotlib#15091 had some interesting points about turbo.

VdBlues and VdGreens

I can't remember where I found these...

@bclehmann
Copy link
Member Author

Does Ctrl+K, Ctrl+D autoformat the document for you?

Yes but it still uses tabs. If I press tab it gets replaced with spaces, but autoformat doesn't care.

I'm not a lawyer, but since we are distributing a derivative work (not the unmodified original work) it looks like it's okay to include in a MIT project:

Great, I'll add it

TLDR; they're mine, but matplotlib's colormaps are way better

Ok, I'll leave them be for now

@bclehmann
Copy link
Member Author

Update

Currently, it looks like this:
image

Additions

I think it's in a pretty good spot, the only thing that seems lacking is the axes, I feel like it could be useful to show a bit more granularity. The easiest way to do that is just to darken the grid, which looks like this:

image

Let me know what you think. Just darken the grid, or put some more work into the axes.

@swharden
Copy link
Member

swharden commented May 24, 2020

Does Ctrl+K, Ctrl+D autoformat the document for you?

Yes but it still uses tabs. If I press tab it gets replaced with spaces, but autoformat doesn't care.

Hm, I guess visual studio is ignoring the format file. In a command window you can

dotnet tool install --global dotnet-format
cd C:\path\to\ScottPlot\src
dotnet format

Currently, it looks like this

This is looking so good! I really love the colormap scalebar on the right. Don't put too much more time into labeling the corners. I think what should happen here is I should figure out a way to resize the data area to fit the heatmap that way we can use the built-in scalebars axis and tick system. I need to refactor the layout system which is why I suggest you don't worry too much about figuring that out because it's a bit thorny and likely to change soon.

In the mean time what do you think about figuring out how to make the heatmap stretch to fill 100% of the viewable area? Maybe this is an interesting intermediate option. If the heatmap describes real data from 0-10 on X and Y, you can plt.Axis(0, 0, 10, 10);, then draw your heatmap with something like stretch: true, and it will fill the data area. This way the axis ticks will actually line up with the heat map... it seems too easy 😈 there may be a catch 🤔

If you want to render the scalebar outside the data area, add a lot of padding to the right (https://swharden.com/scottplot/cookbooks/4.0.32/#customize-figure-figure-padding) and draw on settings.gfxFigure instead of gfxData. I'll make a more elegant solution when I refactor the layout system as described above...

@swharden
Copy link
Member

swharden commented Jun 1, 2020

@Benny121221 this is developing nicely! I actually want to merge this in ASAP, and we can keep it tagged as experimental, and open a new PR to refine it.

Merging small PRs frequently and hiding experimental features behind feature flags avoids merge hell and keeps the project nimble.

... but I might be too late 😝 41 files chanaged? 💀 I'm not a git pro... so I'm not sure when it got out of control or if it was you or me that did it.

If you issue a simple a PR of something I can easily merge, I'm guessing all the future development can just be modifications to the 1 PlottableHeatmap.cs file and the PR will be easy from there. Up to you if you want to try to repair this PR or create a new one. Also if you'd rather me give it a shot, let me know (and stop making commits here) and I'll see what I can do.

@bclehmann
Copy link
Member Author

~40 real commits, and the rest are merge or rebase related. There should be no conflicts

@swharden
Copy link
Member

swharden commented Jun 1, 2020

If it helps, these are the only files that should be modified by this PR

image

If you want to divide and conquer a bit, modifications to the user controls and colormaps could probably be their own PRs. That simplifies the heatmap PR greatly.

@swharden
Copy link
Member

swharden commented Jun 1, 2020

~40 real commits, and the rest are merge or rebase related. There should be no conflicts

Well... I guess I can try the merge and roll it back if we need to.

I think I caused this problem, as I didn't realize those rebases would appear as modified files in the PR

@bclehmann
Copy link
Member Author

Well... I guess I can try the merge and roll it back if it gets weird.
In the future I'll consider frequent rebases an indication things are staring to go off the rails somewhere... I like to review the files changed line by line while merging, but this one's gotten pretty overwhelming

I can cherry-pick the commits, it's not a problem

and make all properties readonly
@swharden swharden merged commit 5066350 into ScottPlot:master Jun 1, 2020
@bclehmann bclehmann mentioned this pull request Jun 1, 2020
@swharden swharden mentioned this pull request Jun 1, 2020
swharden added a commit that referenced this pull request Jun 9, 2020
@oszymczak
Copy link

Hi,

Just wondering if there will be a capability to be able to add a background image or to make the heatmap transparent?

heatmap

Another cool feature I was looking at, is demoed by Azure maps
https://azuremapscodesamples.azurewebsites.net/Heat%20Map%20Layer/Heat%20Map%20Layer%20Options.html

In the layer options tab you can play around with:

  • Radius size
  • Opacity
  • intensity
  • Weight
    image
    image

@bclehmann
Copy link
Member Author

bclehmann commented Jun 11, 2020

@olofszymczak I added transparency and background pictures to a new issue #457.

I don't see much use in expanding the radius of points personally, to me it just makes it less readable. If @swharden disagrees then I'm sure it can make it into a PR

As for intensity and weight I'm not certain I know what they do.

EDIT: Intensity seems to just be a multiplier. Once a user-defined scale is added it will be redundant, as the user can just multiply their inputs themselves

@bclehmann
Copy link
Member Author

If you have more ideas on heatmaps I would suggest commenting on #457 or making a new issue, just so its easier to find your suggestions and input

@bclehmann bclehmann mentioned this pull request Jun 11, 2020
16 tasks
@swharden
Copy link
Member

Hey @olofszymczak, I think @Benny121221 is doing an awesome job with #457 and I agree with their comments from the previous couple of posts.

One thing to keep in mind is that ScottPlot is intended to be a plotting library, with the goal of making it easy to display X/Y data interactively in a 2D coordinate space. In other words, the primary focus of ScottPlot is to create mouse-interactive plots with have labeled X and Y axes and maybe a title. While heatmaps are probably still within this scope, we should temper how many heatmap features we want to support.

There's probably a point where advanced heatmap functionality features merits its own library. Such a library could be massively simpler that ScottPlot since it would focus on only image processing, and not deal with the advanced interactive 2D coordinate and rendering systems that underlies the majority of ScottPlot's code. I'm afraid that diving too deeply into heatmap functionality tilts ScottPlot toward an image processing library, and I'd rather keep it simple and focused and good at one thing: plotting X and Y data.

I'd rather intentionally under-support heatmaps rather than try to do everything heatmap related but end-up doing a bad job at it, or end-up with a heatmap module that's so advanced it's hard to maintain. I don't know what the best balance of features is yet, but I thought I'd share my thought process with the group. Again I'm really excited about how #424 is growing, and looking forward to finding where that ideal balance between features and simplicity will be!

@oszymczak
Copy link

Cool, will add any new ideas/suggestions that I have to #457.

@swharden swharden mentioned this pull request Aug 8, 2020
53 tasks
swharden added a commit that referenced this pull request Oct 18, 2020
simplify constructor, response IDisposable objects in render methods, implement IPlottable #578 (and #424, #441, #457, #458)
@swharden swharden mentioned this pull request Dec 10, 2020
20 tasks
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.

4 participants