Repository navigation
[Q&A] Real-time plot support in WPF #20
Your questionAre real-time plots supported in WPF? I have looked all over the wiki, samples and cookbook but I can't figure out how to update plots like in Avalonia. I tried to do the example in the cookbook with the StreamingSignal, I added the binding to a Figure to my MplChartControl in my .xaml and then I subscribe to my "sf.RenderRequested", where sf = StreamingFigure, but I cannot find how I tell the UI to render my StreamingFigure without explicitly setting inside my Dispatcher.Invoke. Does WPF only support "static" plots? MatPlotLibNet version1.18.0 Code sample (optional)No response |
Replies: 2 comments
|
You found a real gap, and it is ours rather than anything you did wrong. Three of the four native controls ship a streaming counterpart next to the ordinary one — That also explains the trick you had to invent. You do not need it, though. The control re-reads chart.Figure = sf.Figure; // once
sf.RenderRequested += () => Dispatcher.Invoke(() =>
{
sf.ApplyAxisScaling(); // let the axes follow the data
chart.InvalidateVisual(); // "paint again"
});The We are adding the missing WPF control, so this becomes one binding like everywhere else. It goes into |
|
1.18.1 is being published now, and <wpf:MplStreamingChartControl StreamingFigure="{Binding LiveChart}" />Bind the figure once and leave it there — no Tracing your scenario end to end turned up a second thing on the way, in the core package: sf.MinRenderInterval = TimeSpan.FromMilliseconds(100); // ten frames a secondThe wiki page on streaming lists WPF among the hosts now, and the cookbook's streaming page shows the binding for each of them. Thanks again — the report was precise enough to find both. |
1.18.1 is being published now, and
MplStreamingChartControlis in it.Bind the figure once and leave it there — no
nulland back, and no handler of your own. The control subscribes to the figure, marshals the redraw to the dispatcher, scales the axes before each draw, and lets go when it is unloaded.Tracing your scenario end to end turned up a second thing on the way, in the core package:
StreamingFigure.MinRenderIntervalhad a setter, but the clock behind it was started once when the figure was built and never restarted. Asking for a calmer chart — directly or throughBuildStreaming(renderInterval)— quietly kept giv…