Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook: add recipe showing frameless heatmap #3828

Closed
itsmygam3 opened this issue May 14, 2024 · 3 comments
Closed

Cookbook: add recipe showing frameless heatmap #3828

itsmygam3 opened this issue May 14, 2024 · 3 comments
Labels
Help Wanted Scott won't do this soon, but PRs from the community are welcome! ⚠️ HIGH PRIORITY

Comments

@itsmygam3
Copy link

itsmygam3 commented May 14, 2024

Question: For further processing, I need to save the heatmap plot as an image, but when trying to save, white fields are always formed at the edges. How can I fix the code so that I can get an image containing only a graph of a heatmap without extraneous elements?

UPD. At the moment, I found out that the DataBackground field from BackgroundStyle class is responsible for this frame. I was able to change its color, but I need to completely exclude it.
image

ScottPlot Version: 5.0.34

Code Sample:

double[,] data = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

formsPlot1.Plot.HideGrid();
formsPlot1.Plot.Layout.Frameless();
formsPlot1.Plot.Add.Heatmap(data);
formsPlot1.Plot.SaveJpeg("bord.jpg", 400, 400);

panel1.Controls.Add(formsPlot1);
@swharden swharden added the Help Wanted Scott won't do this soon, but PRs from the community are welcome! label May 14, 2024
@swharden swharden changed the title How i can save HeatMap Plot as image without white fields using ScottPlot 5 Heatmap: still has white border when "frameless" mode is enabled May 14, 2024
@swharden
Copy link
Member

Thanks for reporting this @itsmygam3! I suspect this issue relates to axes taking several pixels even though frameless is enabled, but an not 100% sure yet. I'll take a look at this eventually, but if someone from the open source community is able to take a closer look first and creates a PR to fix the problem, I will be happy to review and merge it in good time 👍

@swharden
Copy link
Member

I confirmed this is a heatmap issue (not an axis padding issue) because setting the data area background color shows the heatmap is not filling the whole data area

double[,] data = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

ScottPlot.Plot plot = new();
plot.DataBackground.Color = ScottPlot.Colors.Magenta;
plot.Add.Heatmap(data);
plot.Layout.Frameless();
plot.SaveJpeg("bord.jpg", 400, 400).LaunchFile();

bord

@swharden
Copy link
Member

Actually, I figured it out! Plots have a little bit of padding (margins) around the data area by deafault. Disabling this gets the functionality you're seeking:

double[,] data = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };

ScottPlot.Plot plot = new();
plot.DataBackground.Color = ScottPlot.Colors.Magenta;
plot.Axes.Margins(0, 0); // <------ SET MARGIN TO ZERO
plot.Add.Heatmap(data);
plot.Layout.Frameless();
plot.SaveJpeg("bord.jpg", 400, 400).LaunchFile();

bord

I'll leave this issue open to track adding an example to the cookbook

@swharden swharden changed the title Heatmap: still has white border when "frameless" mode is enabled Cookbook: add recipe showing frameless heatmap May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Scott won't do this soon, but PRs from the community are welcome! ⚠️ HIGH PRIORITY
Projects
None yet
Development

No branches or pull requests

2 participants