alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.23k stars 325 forks source link

gnuplot warning/error: unrecognized option & invalid command #291

Open Extra-Creativity opened 2 years ago

Extra-Creativity commented 2 years ago

Bug category I don't know whether it's a warning or an error.

Describe the bug In Windows 10, I use CMake to install matplot++ and install gnuplot 5.4.4 on its website. I've chosen wxt as default when installing. I just ran the example code:

#include <cmath>
#include <matplot/matplot.h>

int main() {
    using namespace matplot;

    std::vector<double> x = linspace(0, 2 * pi);
    std::vector<double> y1 = transform(x, [](auto x) { return sin(x); });
    std::vector<double> y2 = transform(x, [](auto x) { return sin(x - 0.25); });
    std::vector<double> y3 = transform(x, [](auto x) { return sin(x - 0.5); });
    plot(x, y1, x, y2, "--", x, y3, ":");
    show();
    return 0;
}

However, the cmd Terminal prompts several lines:

gnuplot> se
                line 0: unrecognized option - see 'help set'. 
gnuplot> t terminal wxt title "Figure 1" size 560,420 enhanced font "Sans,10"
                line 0: invalid command                                                  
gnuplot> se
                line 0: unrecognized option - see 'help set'.                                                                                                                                                                                                                                 gnuplot> t terminal wxt title "Figure 1" size 560,420 enhanced font "Sans,10"                                                                                                                    
                line 0: invalid command    
gnuplot> se                                                                                             
                line 101: unrecognized option - see 'help set'.                  
gnuplot> t terminal wxt title "Figure 1" size 560,420 enhanced font "Sans,10"                                                                                                                    
                line 101: invalid command    
gnuplot> se                                                                                             
                line305: unrecognized option - see 'help set'.       
gnuplot> t terminal wxt title "Figure 1" size 560,420 enhanced font "Sans,10"                                                                                                                     
                line 305: invalid command        
gnuplot> se                                                                                                                                                                                      
                line 612: unrecognized option - see 'help set'.                
gnuplot> t terminal wxt title "Figure 1" size 560,420 enhanced font "Sans,10"                                                                                                                  
                line 612: invalid command

It's definitely NOT your intention to produce such lines when running example code. This is also mentioned in issue #243 and discussion #267 ,and both of them have been reported for a long time without ANY valid solution. Besides, when running this code, the plot screen will also flash several times, and I suspect that's related with the error/warning info. The final plot is right, but that's a miserable course to get lots of weird output and flashes to just get one plot.

I regard this project as an alternative to python's matplotlib, so hopefully you can do better and better.

Steps to Reproduce I've mentioned above.

Platform

Environment Details:

coelhona commented 1 year ago

While trying to debug this issue, I found that adding \n in the figure_type.cpp file here:

    void figure_type::run_terminal_init_command() {
         std::stringstream ss;
         auto &terminal = backend_->output_format();
         ss << "\nset terminal " + terminal;

stops the aforementioned errors from showing up in the terminal output. However, the flashing of the plot still happens. Does it make sense for an extra \n in the pipe output to fix the split output of these commands from happening?