Using Matplotlib with wxWidgets C++

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Using Matplotlib with wxWidgets C++

Post by hinet »

Dear wxWidgets Hello,
I am using wx to develop a GUI for serial communication with a microcontroller. The idea is to plot a graph with the data coming from that microcontroller. I am using an external library to plot graphs in an auinotebook, I have many data to plot. So auinotebook, was a convenient object for that. The library is matplotlib-cpp here is a small example code:
https://matplotlib-cpp.readthedocs.io/e ... /docs.html

Code: Select all

#include "../matplotlibcpp.h"
#include <vector>

namespace plt = matplotlibcpp;

int main() {
  // plot(y) - the x-coordinates are implicitly set to [0,1,...,n)
  // note, that plot({..}, {..}) is not supported due to the ambiguous cast
  // of {..} to either std::string or std::vector
  plt::plot({1, 3, 2, 4});
  plt::savefig("minimal.pdf");
}

I don't have any idea how to use this library with wxWidgets, I want to plot many pages in the auinotebook but I don't know to show the grap on the aui page?
here is an example using wxpython, please find the picture below.
I want to do the same thing in C++.

Thank you in advance,
S.Tarik
Attachments
Capture d’écran 2021-04-08 231639.png
Capture d’écran 2021-04-08 231639.png (41.06 KiB) Viewed 2816 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Using Matplotlib with wxWidgets C++

Post by doublemax »

I couldn't find what kind of outputs matplotlib supports, from the sample code i can only see that it can generate a PDF. If it can also create any kind of image/bitmap, you could write a small wrapper class that just takes that image and draws it onto a panel.
https://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
Use the source, Luke!
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

Yes, It could show figures like the picture below.

Here is a sample code:

Code: Select all

#define _USE_MATH_DEFINES // for sin/log
#include "../matplotlibcpp.h"
#include <cmath>
#include <iostream>

namespace plt = matplotlibcpp;

int main() {
  int n = 5000; // 5000 data points
  std::vector<double> x(n), y(n), z(n), w(n, 2);
  for (int i = 0; i < n; ++i) {
    x.at(i) = i * i;
    y.at(i) = sin(2 * M_PI * i / 360.0);
    z.at(i) = log(i);
  }

  plt::figure(); // declare a new figure (optional if only one is used)

  plt::plot(x, y); // automatic coloring: tab:blue
  plt::show(false);
  plt::plot(x, w, "r--");                 // red dashed line
  plt::plot(x, z, {{"label", "log(x)"}}); // legend label "log(x)"

  plt::xlim(0, 1000 * 1000);    // x-axis interval: [0, 1e6]
  plt::title("Standard usage"); // set a title
  plt::legend();                // enable the legend

  plt::savefig("standard.pdf"); // save the figure
  plt::show();
}

Attachments
Capture d’écran 2021-04-08 231639.png
Capture d’écran 2021-04-08 231639.png (6.41 KiB) Viewed 2775 times
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

In python, I am using this code to plot to auinotebook page:
how I could do this using C++?

Code: Select all

class Plot(wx.Panel):
    def __init__(self, parent, id=-1, dpi=None, **kwargs):
        wx.Panel.__init__(self, parent, id=id, **kwargs)
        self.figure = mpl.figure.Figure(dpi=dpi, figsize=(1, 1))
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Realize()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.canvas, 1, wx.EXPAND)
        sizer.Add(self.toolbar, 0, wx.LEFT|wx.ALL | wx.EXPAND)
        self.SetSizer(sizer)
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Using Matplotlib with wxWidgets C++

Post by doublemax »

This is really Matplotlib question. If you find a way to write the data as some kind of bitmap, you can dispay it in wxwidgets. According to this post , you can do it with "imsave", but it seems using a tempfile is the only way.
Use the source, Luke!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Using Matplotlib with wxWidgets C++

Post by doublemax »

hinet wrote: Fri Apr 09, 2021 3:45 pm In python, I am using this code to plot to auinotebook page:
how I could do this using C++?
Does the C++ wrapper have an equivalent to "FigureCanvas"? That that's probably the class you need.
Use the source, Luke!
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

doublemax wrote: Fri Apr 09, 2021 3:47 pm This is really Matplotlib question. If you find a way to write the data as some kind of bitmap, you can dispay it in wxwidgets. According to this post , you can do it with "imsave", but it seems using a tempfile is the only way.
I want real-time plotting for data coming from the ECU. Plotting an image is no the best way I guess. I was trying to use wxMathplot, but the issue is this library couldn't be compiled in wxWidgets 3.1.0. I compiled it with wxWidgets 2.8 but I have to change my wxFormebuilder because 2.8 doesn't support wxstaticbox. Do you know any alternatives?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Using Matplotlib with wxWidgets C++

Post by ONEEYEMAN »

Hi,
2.8 does support wxStaticBox and it works just fine.
What issues you encounter when trying to build the library with 3.0? You should probably try to address them with MatPlotLib developers.

Thank you.
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

ONEEYEMAN wrote: Fri Apr 09, 2021 4:59 pm Hi,
2.8 does support wxStaticBox and it works just fine.
What issues you encounter when trying to build the library with 3.0? You should probably try to address them with MatPlotLib developers.

Thank you.
Hello ONEEYEMAN,

I start my project using wxWidgets 3.1.0, I build my forum using wxFormeBuilder and run it using code blocks.
I compiled the wxWidgets 2.8 to use the exciting form with wxMathplot and I tried to call the forme but, I have this message, please see the picture below.
I shared my code if you want to take a look at it:
https://univcadiayyad-my.sharepoint.com ... g?e=UPUMZT
Thank you in advance,
Attachments
Capture d’écran 2021-04-09 201127.png
Capture d’écran 2021-04-09 201127.png (23.08 KiB) Viewed 2712 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Using Matplotlib with wxWidgets C++

Post by PB »

(I know nothing about wxMathPlot)

What exactly is the issue with wxMathPlot and recent wxWidgets versions?

I have just tried to find the version on GitHub with most recent commit, ended with this:
https://github.com/mkarmona/wxMathPlot

I could build the library as well as build and run samples just fine (wxWidgets master, MSVS 2019 64-bit):
mathplot.png
mathplot.png (57.73 KiB) Viewed 2706 times
One gets many warning due to using deprecated API but it still builds... However, there may be some issues aside from build errors?

EDIT
I could also easily build and run wxMathPlot 0.1.2 straight from SourceForge. All I had to do was change the type for saving wxImage from int to wxBitmapType and replace "::wxLogError" with "wxLogError". The first sample also now seems to display the chart legend correctly, unlike the one I got from GitHub.
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

PB wrote: Fri Apr 09, 2021 6:30 pm (I know nothing about wxMathPlot)

What exactly is the issue with wxMathPlot and recent wxWidgets versions?

I have just tried to find the version on GitHub with most recent commit, ended with this:
https://github.com/mkarmona/wxMathPlot

I could build the library as well as build and run samples just fine (wxWidgets master, MSVS 2019 64-bit):
mathplot.png

One gets many warning due to using deprecated API but it still builds... However, there may be some issues aside from build errors?
I tried to build this library using MinGW, please find the command in the picture below.
To compile I create a wxWidgets3.1.0 empty project static library or dynamic library, and I add the .cpp and .h files.
I tried with the repository GitHub you attached in your response.

Code: Select all

-------------- Build: Debug in testPloter (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -g -IC:\wxWidgets-3.1.4\include -IC:\wxWidgets-3.1.4\lib\gcc_dll\mswu -c C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp -o obj\Debug\mathplot.o
g++.exe -shared -Wl,--output-def=bin\Debug\libtestPloter.def  -Wl,--dll -LC:\wxWidgets-3.1.4\lib\gcc_dll obj\Debug\mathplot.o  -o bin\Debug\testPloter.dll -mthreads  -lwxmsw31u C:\wxWidgets-3.1.4\lib\gcc_dll\libwxbase31ud.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxbase31ud_net.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxbase31ud_xml.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxexpat.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxexpatd.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxjpeg.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxjpegd.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31u.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31u_gl.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_adv.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_aui.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_core.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_gl.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_html.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_media.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_propgrid.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_ribbon.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_richtext.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_stc.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_webview.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxmsw31ud_xrc.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxpng.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxpngd.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxregexu.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxregexud.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxscintilla.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxscintillad.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxtiff.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxtiffd.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxzlib.a C:\wxWidgets-3.1.4\lib\gcc_dll\libwxzlibd.a
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'wxBitmap mpLayer::GetColourSquare(int)':
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:81:32: warning: 'wxBrush::wxBrush(const wxColour&, int)' is deprecated: use wxBRUSHSTYLE_XXX constants [-Wdeprecated-declarations]
   wxBrush brush(filler, wxSOLID);
                                ^
In file included from C:\wxWidgets-3.1.4\include/wx/brush.h:73:0,
                 from C:\wxWidgets-3.1.4\include/wx/dc.h:24,
                 from C:\wxWidgets-3.1.4\include/wx/dcmemory.h:14,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:84,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/brush.h:44:5: note: declared here
     wxBrush(const wxColour& col, int style);
     ^~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'virtual void mpScaleX::Plot(wxDC&, mpWindow&)':
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:806:31: warning: 'void wxPen::SetStyle(int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
           m_pen.SetStyle(wxDOT);
                               ^
In file included from C:\wxWidgets-3.1.4\include/wx/pen.h:84:0,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:83,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/pen.h:62:10: note: declared here
     void SetStyle(int style) { SetStyle((wxPenStyle)style); }
          ^~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:817:33: warning: 'void wxPen::SetStyle(int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
           m_pen.SetStyle(wxSOLID);
                                 ^
In file included from C:\wxWidgets-3.1.4\include/wx/pen.h:84:0,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:83,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/pen.h:62:10: note: declared here
     void SetStyle(int style) { SetStyle((wxPenStyle)style); }
          ^~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'virtual void mpScaleY::Plot(wxDC&, mpWindow&)':
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:1068:31: warning: 'void wxPen::SetStyle(int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
           m_pen.SetStyle(wxDOT);
                               ^
In file included from C:\wxWidgets-3.1.4\include/wx/pen.h:84:0,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:83,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/pen.h:62:10: note: declared here
     void SetStyle(int style) { SetStyle((wxPenStyle)style); }
          ^~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:1079:33: warning: 'void wxPen::SetStyle(int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
           m_pen.SetStyle(wxSOLID);
                                 ^
In file included from C:\wxWidgets-3.1.4\include/wx/pen.h:84:0,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:83,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/pen.h:62:10: note: declared here
     void SetStyle(int style) { SetStyle((wxPenStyle)style); }
          ^~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpWindow::OnMouseMove(wxMouseEvent&)':
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:1327:37: warning: 'wxPen::wxPen(const wxColour&, int, int)' is deprecated: use wxPENSTYLE_XXX constants [-Wdeprecated-declarations]
         wxPen pen(*wxBLACK, 1, wxDOT);
                                     ^
In file included from C:\wxWidgets-3.1.4\include/wx/pen.h:84:0,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:83,
                 from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:
C:\wxWidgets-3.1.4\include/wx/msw/pen.h:59:5: note: declared here
     wxPen(const wxColour& col, int width, int style);
     ^~~~~
In file included from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:24:0:
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpFXYVector::SetData(const std::vector<double>&, const std::vector<double>&)':
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2414:5: note: in expansion of macro 'wxLogError'
     wxLogError(
     ^
In file included from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:17:0:
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h: In constructor 'mpPrintout::mpPrintout(mpWindow*, const wxChar*)':
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.h:1550:13: warning: 'mpPrintout::plotWindow' will be initialized after [-Wreorder]
   mpWindow *plotWindow;
             ^~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2515:21: warning:   base 'wxPrintout' [-Wreorder]
     wxPrintout(title) { }
                     ^
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2512:1: warning:   when initialized here [-Wreorder]
 mpPrintout::mpPrintout(mpWindow *drawWindow, const wxChar *title)
 ^~~~~~~~~~
In file included from C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:24:0:
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpMovableObject::ShapeUpdated()':
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2592:5: note: in expansion of macro 'wxLogError'
     wxLogError(wxT("[mpMovableObject::ShapeUpdated] Error, m_shape_xs and \
     ^
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpCovarianceEllipse::RecalculateShape()':
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2714:5: note: in expansion of macro 'wxLogError'
     wxLogError(
     ^
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2719:5: note: in expansion of macro 'wxLogError'
     wxLogError(
     ^
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2724:5: note: in expansion of macro 'wxLogError'
     wxLogError(
     ^
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2740:5: note: in expansion of macro 'wxLogError'
     wxLogError(
     ^
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpPolygon::setPoints(const std::vector<double>&, const std::vector<double>&, bool)':
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2816:5: note: in expansion of macro 'wxLogError'
     wxLogError(wxT("[mpPolygon] Error: points_xs and points_ys must have the "
     ^
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp: In member function 'void mpBitmapLayer::SetBitmap(const wxImage&, double, double, double, double)':
C:\wxWidgets-3.1.4\include/wx/log.h:1261:36: error: 'wxDO_IF' was not declared in this scope
     wxDO_IF(wxLOG_IS_ENABLED(level))                                          \
                                    ^
C:\wxWidgets-3.1.4\include/wx/log.h:1273:20: note: in expansion of macro 'wxDO_LOG_IF_ENABLED'
 #define wxLogError wxDO_LOG_IF_ENABLED(Error)
                    ^~~~~~~~~~~~~~~~~~~
C:\Users\*********\Documents\Code_Blocks\testPloter\mathplot.cpp:2842:5: note: in expansion of macro 'wxLogError'
     wxLogError(wxT("[mpBitmapLayer] Assigned bitmap is not Ok()!"));
Attachments
Capture d’écran 2021-04-09 201127.png
Capture d’écran 2021-04-09 201127.png (79.6 KiB) Viewed 2698 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Using Matplotlib with wxWidgets C++

Post by PB »

Please take a look at the edit in my previous post describing how I made v0.1.2 from SourceForge build with wxWidgets 3.1.5 in about two minutes. Those errors you get are for the issues I fixed.

Actually, don't. I have just tried building the trunk version from SourceForge and it builds out of the box: https://sourceforge.net/p/wxmathplot/sv ... /mathplot/ (click Download Snapshot to get it). The last commit there is from last year, so it seem there is still some activity there. I still got a couple of warnings about deprecated wxPen/wxBrush constants but those are also super easy to fix.

EDIT
I have verified that trunk from SourceForge builds out of the box with MinGW as well (32-bit, library and samples), using MSYS2 package mingw-w64-i686-toolchain (GCC 10.2).
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

PB wrote: Fri Apr 09, 2021 6:30 pm (I know nothing about wxMathPlot)

What exactly is the issue with wxMathPlot and recent wxWidgets versions?

I have just tried to find the version on GitHub with most recent commit, ended with this:
https://github.com/mkarmona/wxMathPlot

I could build the library as well as build and run samples just fine (wxWidgets master, MSVS 2019 64-bit):
mathplot.png

One gets many warning due to using deprecated API but it still builds... However, there may be some issues aside from build errors?

EDIT
I could also easily build and run wxMathPlot 0.1.2 straight from SourceForge. All I had to do was change the type for saving wxImage from int to wxBitmapType and replace "::wxLogError" with "wxLogError". The first sample also now seems to display the chart legend correctly, unlike the one I got from GitHub.
All I had to do was change the type for saving wxImage from int to wxBitmapType and replace "::wxLogError" with "wxLogError"
Could you clarify please, I could find ::wxLogError in mathplot.c/h,
saving wxImage frome int to wxbitmatType?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Using Matplotlib with wxWidgets C++

Post by PB »

I meant changing the variable type from int to wxBitmapType for type in the definition and declaration of mpWindow::SaveScreenshot(). MP1 sample also needs the same for fileType in MyFrame::OnSaveScreenshot().

Also one needs to remove "::" prefixing wxLogError() calls, in wxWidgets 3.0+ wxLog*() are macros and not functions, so the scope operator is wrong there.

However, do NOT do this. Use the trunk version instead, where more issues seem fixed, see my previous post which you may have missed.
hinet
Experienced Solver
Experienced Solver
Posts: 64
Joined: Mon Aug 08, 2016 9:44 am
Location: France
Contact:

Re: Using Matplotlib with wxWidgets C++

Post by hinet »

PB wrote: Fri Apr 09, 2021 8:20 pm I meant changing the variable type from int to wxBitmapType for type in the definition and declaration of mpWindow::SaveScreenshot(). MP1 sample also needs the same for fileType in MyFrame::OnSaveScreenshot().

Also one needs to remove "::" prefixing wxLogError() calls, in wxWidgets 3.0+ wxLog*() are macros and not functions, so the scope operator is wrong there.

However, do NOT do this. Use the trunk version instead, where more issues seem fixed, see my previous post which you may have missed.
Hello PB,
I really thank you for your help, I compiled the library with my code and wxWidgets 3.1.0, it works.
However, the second part: " Also one needs to remove "::" prefixing wxLogError() calls, in wxWidgets 3.0+ wxLog*() are macros and not functions, so the scope operator is wrong there."
I didn't find a lot of ':: prefixed wxLogError(), I tried to delete one prefix definition but it doesn't compile. Finally, I commented the wxLogError calls to compile the code and move forward a little bit.
please find my log.h
Attachments
log.h
(49.69 KiB) Downloaded 62 times
Post Reply