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

Problem updating heatmaps when buffer changes #3802

Closed
joacorapela opened this issue May 7, 2024 · 3 comments
Closed

Problem updating heatmaps when buffer changes #3802

joacorapela opened this issue May 7, 2024 · 3 comments

Comments

@joacorapela
Copy link

joacorapela commented May 7, 2024

Question: (Ask your question here)
I need a heatmap displaying the content of a 2D buffer, which updates when the buffer is modified. I cannot make the heatmap update without clicking on the heatmap in order to force the update. Is it possible to get heatmap updates without clicking on it? If so, how?

ScottPlot Version: (What NuGet package are you using?)

I am using ScottPlot.Avalonia in a C# standalone application.
PackageReference Include="ScottPlot.Avalonia" Version="4.1.64"

Code Sample: See http://scottplot.net/faq/repro/ for tips about creating reproducible code samples

Unfortunately the code below does not update the heatmap when _buffer is modified by computeMultivariateGaussianPDForGrid. I need to click on the Heatmap to see the updates.

        _plt = new ScottPlot.Plot(400, 400);                                                                                                                                                                                                           
        _hm = _plt.AddHeatmap(_buffer, lockScales: false);
        // computeMultivariateGaussianPDForGrid updates _buffer
        computeMultivariateGaussianPDForGrid(_buffer, m0, S0);
        _hm.Update(_buffer);

Please refer to the constructor MainWindow() and to method OnNext() on this source code for more details.

Thanks, Joaquin

@joacorapela joacorapela changed the title Automatically updating heatmaps when buffer changes Problem updating heatmaps when buffer changes May 7, 2024
@joacorapela
Copy link
Author

The above problem holds when running in Linux and Windows with Avalonia. However, the problem disappears (i.e., heatmaps update automatically not needing mouse clicks) when running on Windows with WinForms.
https://github.com/joacorapela/bayesianLinearRegressionCSharp/tree/master/code/scripts/OnlineBayesianLinearRegressionRxxWinForms

@swharden
Copy link
Member

swharden commented May 9, 2024

I haven't been able to take a closer look yet, but information here may help!

https://scottplot.net/faq/async/

@swharden
Copy link
Member

Hi @joacorapela, I created the following live heatmap app that seems to work on Avalonia on my system (Windows). Does this code also work for you on Linux? If so, maybe you can compare what you do differently and arrive at a solution. If it doesn't work on Linux, let me know and we can open this issue back up and take a look, but I don't do much Linux desktop development so it will be pretty difficult for me to work on this, and I'll have to lean on others in the open source community to offer advice.

using Avalonia.Controls;
using ScottPlot.Avalonia;
using Avalonia.Threading;

namespace Sandbox.Avalonia;

public partial class MainView : UserControl
{
    readonly ScottPlot.Plottables.Heatmap HMap;
    readonly DispatcherTimer Timer = new();
    readonly double[,] HeatmapData;

    public MainView()
    {
        InitializeComponent();

        HeatmapData = ScottPlot.Generate.Sin2D(23, 13, multiple: 3);
        HMap = new ScottPlot.Plottables.Heatmap(HeatmapData);
        AvaPlot.Plot.PlottableList.Add(HMap);

        Timer.Interval = System.TimeSpan.FromMilliseconds(100);
        Timer.Tick += (s, e) => ChangeData();
        Timer.Start();

        AvaPlot.Refresh();
    }

    private void ChangeData()
    {
        System.Random rand = new();
        for (int y = 0; y < HeatmapData.GetLength(0); y++)
        {
            for (int x = 0; x < HeatmapData.GetLength(1); x++)
            {
                HeatmapData[y, x] += rand.NextDouble() - .5;
            }
        }

        HMap.Update();
        AvaPlot.Refresh();
    }
}

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

No branches or pull requests

2 participants