How can I show matplotlib plots seamlessly in the GUI window?
zwm88 opened this issue · 5 comments
I'm wondering how I can draw matplotlib plots to a Canvas?
I guess I can save plots in a memory image, then draw this image to the canvas in TPaintBox.OnPaint method.
But there will be no interaction. And I don't know if I maximize the Window, whether the image will look ugly.
Could anyone provide a matplotlib backend that uses DelphiVCL or DelphiFMX?
I guess that would be a feature request, the backend, something similar to https://github.com/beeware/toga-chart
Qt and Kivy etc. all have the matplotlib backend. @lmbelo
@zwm88 It would be really good. I will investigate it a little more.
If you have started something, we can take it to the discussion and put some work.
I made it for now using TImage, but a backend will be good for interactive mode.
Here is my code:
Height = self.Image1.Height
Width = self.Image1.Width
fig, ax = plt.subplots(figsize = (Width / self.PixelsPerInch, Height / self.PixelsPerInch), dpi = self.PixelsPerInch)
ax.plot(x, y, linewidth=3.0)
plt.legend(['A', 'B', 'C'], loc='upper left')
plt.savefig('test.png', format='png')
self.Image1.Picture.LoadFromFile('test.png')
plt.close()
Seems that TStream is not supported by the DelphiVCL, and I don't know how to set the Image's picture using an image in memory, so I have to use the intermediate file, which is a bit slow.
Yes, this would be a great addon feature. I too got a similar thought few days back and was thinking on ways to do so. As @zwm88 pointed, we shall try to take the plot object and provide it as image by avoiding intermediate step. As Python4Delphi is bi-directional, we can even think of taking of providing the matplotlib as backend for plotting through a component.