alandefreitas / matplotplusplus

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

"pngcairo" doesn't use "size" option #370

Closed ino-josh closed 8 months ago

ino-josh commented 9 months ago

Feature category

The problem When saving, if the format is pngcairo, the size option is not passed to gnuplot. So when you do save("/test.png") or save("/test", "pngcairo"), the resulting image is always 640x480.

The solution I'd like In gnuplot.cpp:

    bool gnuplot::terminal_has_size_option(const std::string &t) {
        // Terminals that have the size option *in the way we expect it to work*
        // This includes only the size option with {width, height} and not
        // the size option for cropping or scaling
        SV_CONSTEXPR std::string_view whitelist[] = {
            "qt",      "aqua",     "caca",    "canvas", "eepic",
            "emf",     "gif",      "jpeg",    "pbm",    "png",
            "sixelgd", "tkcanvas", "windows", "wxt",    "svg"};
        return std::find(std::begin(whitelist), std::end(whitelist), t) !=
               std::end(whitelist);
    }

simplty add "pngcairo" to the list.

According to gnuplot documenation:

set term pngcairo
                     {{no}enhanced} {mono|color}
                     {{no}transparent} {{no}crop} {background <rgbcolor>
                     {font <font>} {fontscale <scale>}
                     {linewidth <lw>} {rounded|butt|square} {dashlength <dl>}
                     {pointscale <ps>}
                     {size <XX>{unit},<YY>{unit}}

and

By default the X and Y sizes are taken to be in pixels...

I believe that satisfies the statement Terminals that have the size option *in the way we expect it to work*

Alternatives I've considered Using the "png" terminal, but it looks like trash compared to "pngcairo" :)

Additional context I am submitting this as an issue as opposed to a pull request in case there is some reason this is the way that it is intentionally, and I just don't know that reason.

alandefreitas commented 9 months ago

That makes sense.

I am submitting this as an issue as opposed to a pull request in case there is some reason this is the way that it is intentionally, and I just don't know that reason.

No. It's not really intentional.