Code Monkey home page Code Monkey logo

sciplot's Introduction

! WARNING ! sciplot has been redesigned and there were breaking API changes between v0.2 and v0.3. See the tutorials and the API documentation for the new version.

Overview

So, you have an amazing C++ application for which you need plotting capabilities. You have searched around and discovered that the available options for C++ plotting libraries is rather limited compared to other programming languages, such as Python, for example, which has matplotlib.

The goal of the sciplot project is to enable you, C++ programmer, to conveniently plot beautiful graphs as easy as in other high-level programming languages. sciplot is a header-only library that needs a C++17-capable compiler, but has no external dependencies for compiling. The only external runtime dependencies are gnuplot-palettes for providing color palettes and a gnuplot executable.

Here is an example of sciplot in action:

#include <sciplot/sciplot.hpp>
using namespace sciplot;

int main(int argc, char** argv)
{
    // Create values for your x-axis
    Vec x = linspace(0.0, 5.0, 100);

    // Create a Plot object
    Plot2D plot1;
    // Set color palette for first Plot
    plot1.palette("paired");
    // Draw a sine graph putting x on the x-axis and sin(x) on the y-axis
    plot1.drawCurve(x, std::sin(x)).label("sin(x)").lineWidth(4);
    // Draw a cosine graph putting x on the x-axis and cos(x) on the y-axis
    plot1.drawCurve(x, std::cos(x)).label("cos(x)").lineWidth(2);

    // Create a second Plot object
    Plot2D plot2;
    // Draw a tangent graph putting x on the x-axis and tan(x) on the y-axis
    plot2.drawCurve(x, std::tan(x)).label("tan(x)").lineWidth(4);

    // Put both plots in a "figure" horizontally next to each other
    Figure figure = {{plot1, plot2}};

    // Create a canvas / drawing area to hold figure and plots
    Canvas canvas = {{figure}};
    // Set color palette for all Plots that do not have a palette set (plot2) / the default palette
    canvas.defaultPalette("set1");

    // Show the canvas in a pop-up window
    canvas.show();

    // Save the plot to a SVG file
    canvas.save("example-readme.svg");
}

After compiling and executing this C++ application, the following plot (example-readme.svg) is produced:

Do you want to change the colors?

Simple - just use method Plot::palette to set your preferred color palette. For example, using plot.palette("parula") in the previous code sets the parula color scheme and produces the following plot:

All available color palettes and their names can be found here. Many thanks to Anna Schneider for this incredible work of art!

sciplot's People

Contributors

allanleal avatar caeruleusaqua avatar hermanzdosilovic avatar horstbaerbel avatar janosgit avatar jpenuchot avatar louisjustintallot avatar ram-z avatar tjanas avatar tomcodemusic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sciplot's Issues

Problem with the figure sizes

Many thanks to the contributions to this nice wrapper to gnuplot with C++.

However, I encounter small problems, i.e., the size of the figure can not be modified. Every try I made with "plt.size(150, 200)" doesn't apply to final results.

image

What's more, when the output type is set as “svg", it seems the figures have been exported with inappropriate figure size.

image

I might need some help to carry on with sciplot. Thanks!

Yours,

Sincerely

Bug: gnuplot::clearpath strips : character from absolute Windows file path

We integrated sciplot in our CI where it automatically plots reports of specific failed numeric unit tests. Now I noticed that this fails when a unit test fails on windows as the path to store the file to is always passed as absolute path, starting as usual on windows with the drive letter followed by a : like D:\path\to\plot.pdf. Now gnuplot::clearpath is called on the path passed in and strips away the : so that it becomes D\path\to\plot.pdf which will make gnuplot fail, since it receives an invalid path.

Since using absolute paths is considered good practice especially for environments where the current working directory is not relative to the executable not being able to use absolute file paths on Windows seems like a bug to me.

As correct file path handling is not trivial and sciplot is a C++ 17 library, why not using std::filesystem::path instead of a raw string and let the standard library ensure that the path is valid?

updating the current plot without opening a new window

Hello,
Thanks for this useful library I appreciate your work and effort.
I'm looking for a way to update the plot's data without the need to call plot.show() everytime.
i think this issue is related #56 . is there anyway to do this?
Thanks

Provision to add markers to Plot

Dear author,
I am trying to put marker in the plot, but didn't find any option to do that.
kindly let me know if there is such option existing.

Regards,

Include points with missing data

Hello all,

I'd like to be able to draw plots with missing data points, according to the functionality described in http://gnuplot.sourceforge.net/docs_4.2/node172.html.

Currently, what I'm able to do, is this:

std::vector<int> xVals = {1, 2, 3, 4, 5};
std::vector<int> yVals = {10, 12, 8, 15, 3};

Plot plot;
plot.autoclean(false);
plot.drawPoints(xVals, yVals);  // This could be any draw command.
plot.savePlotData();

This creates the plot0.dat file with the entries

1 10
2 12
3 8
4 15
5 3

in which I can replace one or more of the y values with '?', such that a subsequent program with the structure

Plot plot2;
plot2.gnuplot("set datafile missing '?'");
plot2.draw("'plot0.dat'", "1:($2)", "linespoints");
plot2.show();

will create a plot with gaps at the places, in which data is missing (e.g. let's assume, that the value 8 was not existent):
plotwithgaps

However, this is quite tedious and can only be done by hand, since I'm not sure, how to include the gap character in my original data vectors.

So my questions would be:

  1. Is it possible (or thinkable) that there is something like a draw(x, y, using, with) command which, instead of taking data from a .dat file, takes the vectors as input or, alternatively, that first the plot data is generated and stored (using savePlotData()) and then loaded with the existing draw(what, using, with) command?
  2. How could the problem of special characters in the data vectors be solved efficiently, such that missing data can be interpreted /added/marked correctly in the data set? AFAIK, heterogeneous containers are a bit of a hassle in plain C++. Something like setting missing data to INT_MAX and streaming the vectors to the data file with a conditional like current == INT_MAX ? "?" : std::to_string(current)?

Add arrows to axis-end

Hi,

I am sorry, if I'm just too dumb to find it, but I use sciplot for my bachelor-thesis, and it would increase the quality of the produced plots, if one could add arrows at the end of the coordinate-axises.
Is there a possibility to do this?

Other than that, i have to say, that sciplot is the best solution to make plots with c++ that I could find so far, thanks alot for giving this possibility.

Thank you in advance

Add custom plot command

Hi all,

currently, the plot commands are compiled using the DrawSpecs, containing values for what, using and with, which are subsequently parsed and at least linestyle and linewidth are filled in.

Now, I have a very specific case, in which I'd like to customize the plot command even more and especially the linestyle parameter clashes with my setup (gnuplot complains about "duplicated or contradicting arguments", which vanishes, when I remove it by hand).

Is there a possibility to remove parts of the m_drawspecs or to add custom plot commands? If not, what would be a suitable place to add this?

How to show grid in plot?

How can I show grid.

#include <sciplot/sciplot.hpp>
using namespace sciplot;
`int main(int argc, char** argv)
{
    // Create a vector with values from 0 to pi divived into 200 uniform intervals for the x-axis
    Vec x = linspace(0.0, PI, 200);

    // Create a Plot object
    Plot plot;

    // Set the x and y labels
    plot.xlabel("x");
    plot.ylabel("y");

    // Set the x and y ranges
    plot.xrange(0.0, PI);
    plot.yrange(0.0, 1.0);

    plot.grid().show(); // I THOUGHT IT SHOULD WORK WITH DEFAULT VALUES:

    // Set the legend to be on the bottom along the horizontal
    plot.legend()
        .atOutsideBottom()
        .displayHorizontal()
        .displayExpandWidthBy(2);

    // Plot sin(i*x) from i = 1 to i = 6
    plot.drawCurve(x, std::sin(1.0 * x)).label("sin(x)");
    plot.drawCurve(x, std::sin(2.0 * x)).label("sin(2x)");
    plot.drawCurve(x, std::sin(3.0 * x)).label("sin(3x)");
    plot.drawCurve(x, std::sin(4.0 * x)).label("sin(4x)");
    plot.drawCurve(x, std::sin(5.0 * x)).label("sin(5x)");
    plot.drawCurve(x, std::sin(6.0 * x)).label("sin(6x)");

    // Show the plot in a pop-up window
    plot.show();

    // Save the plot to a PDF file
    plot.save("example-sine-functions.pdf");`

Colormap for show matrix

Hi,
Thanks for your useful project. I have question: How I could implement a matrix with colormap by this project? Is it possible?

I couldn't find any example so I post this issue.

I hope for your answer.

Thanks again

Are Log Plots available?

First of all: Thanks for the library, it is indeed very handy!

I have search for a possibility to make log-plots, but did find one. So apologies if I missed that, but this would be a very nice feature, even though it is not very difficult to do it by hand.

Multiplot should also work if we define subplot before to add curves

This example works:
https://github.com/sciplot/sciplot/blob/master/examples/example-multiplot.cpp

But this code should give same result. Currently it does not work.
It is in this case difficult to manipulate object or to do a wrapping.

   sciplot::Vec x = sciplot::linspace(0.0, 5.0, 200);

    // Create 4 different plots
    sciplot::Plot plot0;
    sciplot::Plot plot1;
    sciplot::Plot plot2;
    sciplot::Plot plot3;

    // Use the previous plots as sub-figures in a larger 2x2 figure.
    sciplot::Figure fig = { { plot0, plot1 }, { plot2, plot3 } };

    
    plot0.drawCurve(x, std::sin(x)).label("sin(x)");
    plot0.drawCurve(x, std::cos(x)).label("cos(x)");

    plot1.drawCurve(x, std::cos(x)).label("cos(x)");

    plot2.drawCurve(x, std::tan(x)).label("tan(x)");

    plot3.drawCurve(x, std::sqrt(x)).label("sqrt(x)");
 
    fig.title("Trigonometric Functions");
    fig.palette("dark2");

Use datetime strings on x axis

Hi,

in plain gnuplot I can have some data.dat file like this:

2021-10-10_1200  3.2
2021-10-11_1300  5.5
2021-10-12_1234  -4.7
2021-10-12_1345  -1.0
2021-10-13_1140  1.2
2021-10-13_1240  2.2
2021-10-13_1340  6.9

And using a script like

set xdata time
set timefmt "%Y-%m-%d_%H%M"
set format x "%m/%d %H:%M"
set xrange ["2021-10-10_0600":"2021-10-13_2000"]
plot "data.dat" using 1:2

I get
grafik

So I can nicely format the axis labels and I can also scale them from min to max.

If I try the same with sciplot

#include <sciplot/sciplot.hpp>
using namespace sciplot;

int main()
{
 std::vector<std::string> xTime =
  {
    "2021-10-10_1200",
    "2021-10-11_1300",
    "2021-10-12_1234",
    "2021-10-12_1345",
    "2021-10-13_1140",
    "2021-10-13_1240",
    "2021-10-13_1340"
  };
    
  std::vector<float> yTime = {3.2, 5.5, -4.7, -1.0, 2.1, 2.2, 6.9};
    
  Plot plot;
  plot.autoclean(false);
  
  plot.gnuplot("set xdata time");                  
  plot.gnuplot("set timefmt '\"%Y-%m-%d_%H%M\"'");    // Single quotes are needed, because the data file is generated with quotes around the time values
  plot.gnuplot("set format x \"%m/%d %H:%M\""); 
  plot.xrange("'\"2021-10-10_0600\"'", "'\"2021-10-13_2000\"'"); // Quotes needed here as well
  
  plot.drawPoints(xTime, yTime);
  plot.show();
}

I only get "show0.plt" line 77: Can't plot with an empty x range!

If I only plot the values without specifying format x and xrange, I get evenly spaced data points, regardless of their "actual" distance. Am I doing something wrong using the library or does sciplot struggle with datetime values, because they are interpreted differently?

I also noticed, that string values on the X axis are always passed as 0:2:xtic(1) for the plot command. Could this be a problem?

Pallete -> palette

Throughout the repo, the word pallete should be replaced with palette :)

Add "canvas" class to handle settings / show / save

plot and multiplot have some stuff in common that should go to a "document" / "canvas" (name suggestion) class. You could add multiplots and plots there and move settings like the output size there too. The document could do the file handling an cleanup and would have the show() and save() methods.
This structure better reflects what you can do in gnuplot and remove code duplication.

StringOrDouble is using std::to_string

std::to_string uses regional format, so 0.0 will be translated to "0,0' instead of "0.0" if format is Russian or Deutsch, which will result in error in gnuplot, so nothing will be drawed.

No PlotSpec::use() option anymore

Am I mistaken, or was this lost on the way to 0.2?
You could call

Plot p;
p.draw(x,y).use(sciplot::plotspecs::USE_AUTO, 2, sciplot::plotspecs::USE_AUTO, 1);

Is there an equivalent or should I add something?

#warning is not a valid preprocessor directive; code cannot compile on MSVC

#72 (merged by 49b3e22) introduced a bug with the #warning preprocessor directive.

This is not a valid preprocessor directive according to the C++ language standard. GCC supports it as an extension, but Microsoft's C++ compiler (as bundled with Visual Studio) does not. Because preprocessor directives that are not supported result in an error, rather than the compiler simply ignoring them (with a special exception made for #pragma), this prevents the code from being compiled with Microsoft's compiler (MSVC) at all. All you get is error C1021:

C1021: invalid preprocessor command 'warning'

On MSVC, you should be using #pragma message to generate a compile-time warning. (This is one of those rare cases where MSVC is actually doing the standards-complaint thing and using a #pragma for optional, implementation-specific features.)

The simplistic cross-platform solution is:

// We check if windows.h. is already included, as this might break compilation. See: https://github.com/sciplot/sciplot/issues/70
#ifdef _WINDOWS_
    #ifdef _MSC_VER
        #pragma message(__FILE__ "(): warning: You might run into compiler errors if windows.h is included before sciplot.hpp! See: https://sciplot.github.io/known_issues/")
    #else
        #warning You might run into compiler errors if windows.h is included before sciplot.hpp! See: https://sciplot.github.io/known_issues/
    #endif  // _MSC_VER
#endif  // _WINDOWS_

Note that the formatting used for #pragma message on MSVC allows the IDE to recognize the message as a warning, and double-clicking on it in the "Output" or "Error List" windows will even take you directly to the affected file. (Original credit for this trick goes to James McNellis.)

Technically, this isn't portable, either, as it unconditionally uses #warning on any compiler that is not MSVC. It should probably only be using #warning on any compiler that reports being GCC-compatible (e.g., #ifdef __GNUC__), but support for #warning is more widespread than just GCC and those that emulate it. MSVC is the major "odd one out" here, so this is the minimal solution for the problem. If you want complete portability, look into doing what Hedley does, as described by its author here: https://stackoverflow.com/a/49469158

Use CamelCase to improve code and usage

My case for CamelCase (pun intended):

I can understand the reasoning behind keeping the syntax close to gnuplot, but consider this example (from enum.hpp):

  • "nocase": The enum / class is named "fillorder" -> You can't name the "set" method fillorder (though that's the gnuplot name) -> You have to name it "fillordertype" (which is unnecessary).
  • "snake_case": The enum / class is named "fill_order" -> set method can be fillorder.
  • "CamelCase": The enum / class is named "FillOrder" -> set method is fillOrder(FillOrder value). Imo this is the best option, as the syntax is the most similar.

This goes for a couple of the sciplot construct. CamelCase is also widely accepted in the C/C++ world (as is snake_case, see google, stackoverflow, github, CppCoreGuidelines). And after all it is C++-users using the library, not just gnuplot users, and they are used to that style.

doxystrap and gnu-palettes not clonable

git clone https://github.com/sciplot/sciplot --recursive tells me it can't clone / read the submodules (german, but you'll get the idea):

bla@PC:~/Software$ git clone https://github.com/sciplot/sciplot --recursive
Klone nach 'sciplot' ...
remote: Enumerating objects: 847, done.
remote: Counting objects: 100% (847/847), done.
remote: Compressing objects: 100% (397/397), done.
remote: Total 2279 (delta 432), reused 649 (delta 388), pack-reused 1432
Empfange Objekte: 100% (2279/2279), 2.44 MiB | 3.72 MiB/s, fertig.
Löse Unterschiede auf: 100% (1602/1602), fertig.
Submodul 'deps/doxystrap' ([email protected]:allanleal/doxystrap) für Pfad 'deps/doxystrap' in die Konfiguration eingetragen.
Submodul 'deps/gnuplot-palettes' ([email protected]:sciplot/gnuplot-palettes) für Pfad 'deps/gnuplot-palettes' in die Konfiguration eingetragen.
Klone nach '/home/me/Software/sciplot/deps/doxystrap' ...
Warning: Permanently added the RSA host key for IP address '140.82.121.4' to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Konnte nicht vom Remote-Repository lesen.

Bitte stellen Sie sicher, dass die korrekten Zugriffsberechtigungen bestehen
und das Repository existiert.
fatal: Klonen von '[email protected]:allanleal/doxystrap' in Submodul-Pfad '/home/me/Software/sciplot/deps/doxystrap' fehlgeschlagen.
Fehler beim Klonen von 'deps/doxystrap'. Weiterer Versuch geplant
Klone nach '/home/me/Software/sciplot/deps/gnuplot-palettes' ...
[email protected]: Permission denied (publickey).
fatal: Konnte nicht vom Remote-Repository lesen.

Bitte stellen Sie sicher, dass die korrekten Zugriffsberechtigungen bestehen
und das Repository existiert.
fatal: Klonen von '[email protected]:sciplot/gnuplot-palettes' in Submodul-Pfad '/home/me/Software/sciplot/deps/gnuplot-palettes' fehlgeschlagen.
Fehler beim Klonen von 'deps/gnuplot-palettes'. Weiterer Versuch geplant
Klone nach '/home/me/Software/sciplot/deps/doxystrap' ...
[email protected]: Permission denied (publickey).
fatal: Konnte nicht vom Remote-Repository lesen.

Bitte stellen Sie sicher, dass die korrekten Zugriffsberechtigungen bestehen
und das Repository existiert.
fatal: Klonen von '[email protected]:allanleal/doxystrap' in Submodul-Pfad '/home/me/Software/sciplot/deps/doxystrap' fehlgeschlagen.
Zweiter Versuch 'deps/doxystrap' zu klonen fehlgeschlagen, breche ab.

The submodules are still in .gitmodules did you mean to remove them?

Is there an easy way to draw a plane?

Is is planned to add some function to Plot3D class like drawPlane in future?
What is the best way to draw a plane now until such a function is not added?
Thank you :)

plot.show() should not open a new figure if already show

Example

    Vec x = linspace(0.0, 5.0, 100);
   Plot plot;
   plot.palette("set2");
   plot.drawCurve(x, std::sin(x)).label("sin(x)").lineWidth(4);
   plot.show();
   plot.show();
   plot.show();

Expected behavior: only one gnuplot should be open.

Fix font size / default fonts

Setting a font, when the user has not specified a font, is not always a good idea:
Bildschirmfoto von 2020-06-26 11-42-47
This is due to the font size being an absolute value and not relative to canvas size. Not that the example above does not set a single font or font size!

There is no way to "unset" the font, so it might make sense to only add font settings when the user specifically sets a font. Also setting only the font, but not the size might be possible so fonts resize depending on canvas size.

Great idea!

I love the idea of this repo! Indeed I have massively struggled with this topic, and my best (albeit horrible) solution has been embedding Python with pybind11 and then calling into matplotlib. It works, but convenient it ain't. Is this linux-only? I live in the big three more OS or less evenly. Currently 50% linux, 50% windows.

Can't compile code

I included the sciplot header in one of my files and tried to compile with clang++ and with g++ using the commands

g++ file.cpp -Iinclude -lpthread -o file.out -std=c++17
clang++ file.cpp -Iinclude -lpthread -o file.out -std=c++17

I used cmake to install to the directory which I'm currently in so the flag "-I" points to the include directory that was generated by cmake.


$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang++ --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

The errors I get are all in Utils.hpp

include/sciplot/Utils.hpp:124:68: error: subscripted value is neither array nor pointer
  124 | constexpr auto isStringVector = isString<decltype(std::declval<V>()[0])>;

include/sciplot/Utils.hpp:115:23: error: request for member ‘size’ in ‘v’, which is of non-class type ‘const long double’
  115 |     return std::min(v.size(), minsize(args...));

include/sciplot/Utils.hpp:147:28: error: subscripted value is neither array nor pointer
  147 |     out << escapeIfNeeded(v[i]) << " ";

Can someone help me?

logscale-command has no effect

I tried to plot an logarithmic x-axis. After I found the corresponding example ("Using logarithmic axes" from "https://sciplot.github.io/tutorials/#using-logarithmic-axes"), i tried plotting the example itself (copy-paste the code), which plots without errors, but the axis is normal, not logarithmic.

I have no idea, why the command is compiled without errors, still there is no effect visible. Especially because everything else works fine.

Are there maybe specific requirements for using this feature?

Thank you in advance for any help. =)

OS: Arch Linux
Compiler: g++
Flags: -std=c++17
Includes: -I/usr/include/python3.9/ -I/usr/lib/python3.9/site-packages/numpy/core/include/ -I./include/

This last include are the sciplot-headers itself. I do want to mention again, that everything except this worked with ease so far, I had no problems.

example-logarithmic-axes.pdf

I'm sorry, if i missed to add needed information, i'll add everything, that might be needed/requested...

filledcurve support

Adding filling to a curve currently doesn't work.

For example:

plot.drawCurveWithPoints(x, y).label(name).fillSolid();

yields the following error:

plot     'plot1.dat' index 0 title 'hello_world' with linespoints linestyle 1 linewidth 2 fillstyle solid
                                                                                          ^
"show1.plt" line 72: unexpected or unrecognized token: fillstyle

Same error when using fillColor("red") instead of fillSolid() or in combination with it.

I guess this is because gnuplot expects these parameters to be given with a filledcurve plot style?

See: http://www.gnuplot.info/docs_4.2/node245.html

Interactive Plots

Hello all,

I often have the case that I want to zoom into my plots afterwards.
Currently the -persist parameter of gnuplot is used to keep the plot window open.

This has the disadvantage that the window is no longer interactive.

If you add the "Pause" command at the end of the gnuplots script instead, the whole thing remains interactive.
(http://gnuplot.info/docs_4.2/node99.html)

The following challenges still exist:

  • gnuplot command is blocking --> thread or subprocess

    • subprocess would probably be better, unfortunately I don't know any STD implementation for this, in boost there seems to be a solution.
  • gnuplot is terminated as soon as the *,dat or *.plt data is deleted or modified (at least under windows)

SCIPLOT in Window Form Application

I need to plot graphs in window aplication. I tried to use sciplot. It works fine in console application, but in window application, i am getting errors.

VStudio 19

ISO C++17 Standard (/std:c++17)

#include <windows.h>

#include <sciplot\sciplot.hpp> // Just include header and getting error

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PWSTR pCmdLine, int CmdShow) {

    MessageBoxW(NULL, L"First plot", L"First", MB_OK);

    return 0;
}



Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0040	expected an identifier	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Default.hpp	40	
Error	C2059	syntax error: 'constant'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Default.hpp	40	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	137	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	137	
Error	C2059	syntax error: ')'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	137	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	151	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	151	
Error	C2059	syntax error: ')'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	151	
Error	C2589	'constant': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	207	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	207	
Warning	C4244	'argument': conversion from 'double' to 'size_t', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	212	
Error	C2589	'constant': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	259	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	259	
Warning	C4244	'argument': conversion from 'double' to 'size_t', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Figure.hpp	264	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\FillSpecsOf.hpp	142	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\FillStyleSpecs.hpp	120	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\FillStyleSpecs.hpp	120	
Error	C2059	syntax error: ')'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\FillStyleSpecs.hpp	120	
Warning	C4267	'argument': conversion from 'size_t' to 'int', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Plot.hpp	710	
Warning	C4267	'argument': conversion from 'size_t' to 'int', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Plot3D.hpp	409	
Error	C2589	'constant': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	237	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	237	
Warning	C4244	'argument': conversion from 'double' to 'size_t', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	242	
Error	C2589	'constant': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	277	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	277	
Warning	C4244	'argument': conversion from 'double' to 'size_t', possible loss of data	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\PlotBase.hpp	282	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\TicsSpecsMinor.hpp	78	
Error	C2062	type 'unknown-type' unexpected	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\TicsSpecsMinor.hpp	78	
Error	C2059	syntax error: ')'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\specs\TicsSpecsMinor.hpp	78	
Error	C2589	'(': illegal token on right side of '::'	WinAPI_TST	E:\FAROAPI\WinAPI_TST\sciplot\Utils.hpp	120	

Move plot legend above plot

Hi,
thanks for this library, it is awesome.
I have a question, can the plot legend be moved above the plot itself? I have rather wide (but low) legend and want to have it above the plot. So far I managed to make it transparent (text is no longer readable) or move it next to plot (but that creates big white area).

Make issue template

So the the users provide the minimum of necessary info. Suggestions go here

Has 3D plotting been removed?

I was able to run/create the 2D graphs (drawing them as well as saving to .PDF and viewing in a browser). However, when I copy/paste the 3D Helix code, Plot3D is not found. Has 3D plotting been removed from this library?

The specific example is here:

#include <sciplot/sciplot.hpp>

using namespace sciplot;

int main(int argc, char** argv)
{
    // Create a vector with values from 0 to 100 divived into 2000 uniform intervals for the z-axis
    Vec z = linspace(0.0, 100.0, 2000);

    // Construct x and y for each z so that a helix curve is defined
    std::vector<double> x,y;
    double c = 2;
    double r = 1;

    for(auto val : z) {
        x.push_back(r*cos(val/c));
        y.push_back(r*sin(val/c));
    }

    // Create a Plot3D object
    Plot3D plot;                         // !! Plot3D not found ? !! //

    // Set the x, y, z labels
    plot.xlabel("x");
    plot.ylabel("y");
    plot.zlabel("z");

    // Clear all borders and set the visible ones
    plot.border().clear();
    plot.border().bottomLeftFront();
    plot.border().bottomRightFront();
    plot.border().leftVertical();

    // This disables the deletion of the created gnuplot script and data file.
    plot.autoclean(false);

    // Change its palette
    plot.palette("dark2");

    // Draw the helix curve
    plot.drawCurve(x, y, z).label("helix").lineColor("orange");

    // Show the plot in a pop-up window
    plot.show();

    // Save the plot to a PDF file
    plot.save("example-3d-helix.pdf");
}

First code execution of example code gives error C2039

Hello,

  • I installed gnuplot.
  • I created a new blank project in Visual Studio Community 2017.
  • Then copied sciplot folder into my dependencies folder of my project.
  • I added the sciplot folder into my include directories in project settings.
  • I copied the example code into my project file and tried to run it but got errors.

program code here:
`

#include <sciplot/sciplot.hpp>
using namespace sciplot;

int main()
{
	// Create values for your x-axis
	const vec x = linspace(0.0, 5.0, 100);

	// Create a plot object
	plot plt;

	// Set its palette
	plt.palette("set2");

	// Draw a sine graph putting x on the x- and sin(x) on the y-axis
	plt.draw(x, std::sin(x)).title("sin(x)").linewidth(8);

	// Draw a cosine graph putting x on the x- and cos(x) on the y-axis
	plt.draw(x, std::cos(x)).title("cos(x)").linewidth(8);

	// Show the plot
	plt.show();

	// Save the plot to a PDF file
	plt.save("figure.pdf");
}

`

These are the errors, not from my main program file, but from sciplot include files, specifically util.hpp

_
..\dependencies\sciplot\util.hpp(281): error C2039: 'remove_if': is not a member of 'std'
..\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\valarray(16): note: see declaration of 'std'
..\dependencies\sciplot\util.hpp(281): error C3861: 'remove_if': identifier not found

_
then several C4244 warnings follow these which may just be result of the above errors.

Since this is a brand new blank project and I just copied the example code provided, I'm not really sure what's going wrong here.
Maybe I just missed something in project settings that I was supposed to do? C2039 I feel like is usually a circular dependency issue but I don't have any other code/files beside what I copied.

I read on Microsoft documentation that C2039 can sometimes be resolved by putting the include line of code inside namespace std but I tried doing that in util.hpp like so:
namespace std { #include <cstdlib> };
This did not fix the issue, so I reverted it back to how util.hpp was originally.

I feel like I must've missed something simple in project settings or goofed something here but I am missing it. Any help would be greatly appreciated. Sciplot looks good, would love to try it out.

Thanks much!

Having trouble installing

I followed your installation.md guide and used the makefile approach, but upon trying out the sample code in the readme I get a big error.
I am trying to use the library on windows with wsl, is this impossible perhaps?

In file included from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Utils.hpp:121:32: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’?
  121 | constexpr auto isString = std::is_same_v<std::decay_t<T>, std::string>;
      |                                ^~~~~~~~~
      |                                is_same
/usr/local/include/sciplot/Utils.hpp:121:57: error: expected primary-expression before ‘,’ token
  121 | constexpr auto isString = std::is_same_v<std::decay_t<T>, std::string>;
      |                                                         ^
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:39:21: error: ‘variant’ in namespace ‘std’ does not name a template type
   39 | using PlotXD = std::variant<Plot, Plot3D>;
      |                     ^~~~~~~
/usr/local/include/sciplot/Figure.hpp:39:16: note: ‘std::variant’ is only available from C++17 onwards
   39 | using PlotXD = std::variant<Plot, Plot3D>;
      |                ^~~
/usr/local/include/sciplot/Figure.hpp:46:62: error: ‘PlotXD’ was not declared in this scope; did you mean ‘Plot3D’?
   46 |     Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots);
      |                                                              ^~~~~~
      |                                                              Plot3D
/usr/local/include/sciplot/Figure.hpp:46:62: error: template argument 1 is invalid
/usr/local/include/sciplot/Figure.hpp:46:68: error: template argument 1 is invalid
   46 |     Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots);
      |                                                                    ^~
/usr/local/include/sciplot/Figure.hpp:49:42: error: ‘PlotXD’ was not declared in this scope; did you mean ‘Plot3D’?
   49 |     Figure(const std::vector<std::vector<PlotXD>>& plots);
      |                                          ^~~~~~
      |                                          Plot3D
/usr/local/include/sciplot/Figure.hpp:49:42: error: template argument 1 is invalid
/usr/local/include/sciplot/Figure.hpp:49:42: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:49:48: error: template argument 1 is invalid
   49 |     Figure(const std::vector<std::vector<PlotXD>>& plots);
      |                                                ^~
/usr/local/include/sciplot/Figure.hpp:49:48: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:49:5: error: ‘sciplot::Figure::Figure(const int&)’ cannot be overloaded with ‘sciplot::Figure::Figure(const int&)’
   49 |     Figure(const std::vector<std::vector<PlotXD>>& plots);
      |     ^~~~~~
/usr/local/include/sciplot/Figure.hpp:46:5: note: previous declaration ‘sciplot::Figure::Figure(const int&)’
   46 |     Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots);
      |     ^~~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:124:29: error: ‘PlotXD’ was not declared in this scope; did you mean ‘Plot3D’?
  124 |     std::vector<std::vector<PlotXD>> m_plots;
      |                             ^~~~~~
      |                             Plot3D
/usr/local/include/sciplot/Figure.hpp:124:29: error: template argument 1 is invalid
/usr/local/include/sciplot/Figure.hpp:124:29: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:124:35: error: template argument 1 is invalid
  124 |     std::vector<std::vector<PlotXD>> m_plots;
      |                                   ^~
/usr/local/include/sciplot/Figure.hpp:124:35: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:130:73: error: ‘PlotXD’ was not declared in this scope; did you mean ‘Plot3D’?
  130 | inline Figure::Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots)
      |                                                                         ^~~~~~
      |                                                                         Plot3D
/usr/local/include/sciplot/Figure.hpp:130:73: error: template argument 1 is invalid
/usr/local/include/sciplot/Figure.hpp:130:79: error: template argument 1 is invalid
  130 | inline Figure::Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots)
      |                                                                               ^~
/usr/local/include/sciplot/Figure.hpp: In constructor ‘sciplot::Figure::Figure(const int&)’:
/usr/local/include/sciplot/Figure.hpp:134:26: error: request for member ‘size’ in ‘plots’, which is of non-class type ‘const int’
  134 |     m_layoutrows = plots.size();
      |                          ^~~~
/usr/local/include/sciplot/Figure.hpp:136:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  136 |     for(const auto& row : plots)
      |                           ^~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:136:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  136 |     for(const auto& row : plots)
      |                           ^~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:139:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  139 |     for(const auto& row : plots)
      |                           ^~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:139:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  139 |     for(const auto& row : plots)
      |                           ^~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:140:17: error: request for member ‘emplace_back’ in ‘((sciplot::Figure*)this)->sciplot::Figure::m_plots’, which is of non-class type ‘int’
  140 |         m_plots.emplace_back(row.begin(), row.end());
      |                 ^~~~~~~~~~~~
/usr/local/include/sciplot/Figure.hpp: At global scope:
/usr/local/include/sciplot/Figure.hpp:143:53: error: ‘PlotXD’ was not declared in this scope; did you mean ‘Plot3D’?
  143 | inline Figure::Figure(const std::vector<std::vector<PlotXD>>& plots)
      |                                                     ^~~~~~
      |                                                     Plot3D
/usr/local/include/sciplot/Figure.hpp:143:53: error: template argument 1 is invalid
/usr/local/include/sciplot/Figure.hpp:143:53: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:143:59: error: template argument 1 is invalid
  143 | inline Figure::Figure(const std::vector<std::vector<PlotXD>>& plots)
      |                                                           ^~
/usr/local/include/sciplot/Figure.hpp:143:59: error: template argument 2 is invalid
/usr/local/include/sciplot/Figure.hpp:143:8: error: redefinition of ‘sciplot::Figure::Figure(const int&)’
  143 | inline Figure::Figure(const std::vector<std::vector<PlotXD>>& plots)
      |        ^~~~~~
/usr/local/include/sciplot/Figure.hpp:130:8: note: ‘sciplot::Figure::Figure(const int&)’ previously defined here
  130 | inline Figure::Figure(const std::initializer_list<std::initializer_list<PlotXD>>& plots)
      |        ^~~~~~
/usr/local/include/sciplot/Figure.hpp: In member function ‘void sciplot::Figure::saveplotdata() const’:
/usr/local/include/sciplot/Figure.hpp:190:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  190 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:190:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  190 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:192:36: error: ‘get_if’ is not a member of ‘std’
  192 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                    ^~~~~~
/usr/local/include/sciplot/Figure.hpp:192:47: error: expected primary-expression before ‘>’ token
  192 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                               ^
/usr/local/include/sciplot/Figure.hpp:194:43: error: ‘get_if’ is not a member of ‘std’
  194 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                           ^~~~~~
/usr/local/include/sciplot/Figure.hpp:194:56: error: expected primary-expression before ‘>’ token
  194 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                                        ^
/usr/local/include/sciplot/Figure.hpp: In member function ‘void sciplot::Figure::show() const’:
/usr/local/include/sciplot/Figure.hpp:219:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  219 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:219:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  219 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:221:36: error: ‘get_if’ is not a member of ‘std’
  221 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                    ^~~~~~
/usr/local/include/sciplot/Figure.hpp:221:47: error: expected primary-expression before ‘>’ token
  221 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                               ^
/usr/local/include/sciplot/Figure.hpp:223:43: error: ‘get_if’ is not a member of ‘std’
  223 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                           ^~~~~~
/usr/local/include/sciplot/Figure.hpp:223:56: error: expected primary-expression before ‘>’ token
  223 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                                        ^
/usr/local/include/sciplot/Figure.hpp: In member function ‘void sciplot::Figure::save(const string&) const’:
/usr/local/include/sciplot/Figure.hpp:274:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  274 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:274:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  274 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:276:36: error: ‘get_if’ is not a member of ‘std’
  276 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                    ^~~~~~
/usr/local/include/sciplot/Figure.hpp:276:47: error: expected primary-expression before ‘>’ token
  276 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                               ^
/usr/local/include/sciplot/Figure.hpp:278:43: error: ‘get_if’ is not a member of ‘std’
  278 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                           ^~~~~~
/usr/local/include/sciplot/Figure.hpp:278:56: error: expected primary-expression before ‘>’ token
  278 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                                        ^
/usr/local/include/sciplot/Figure.hpp: In member function ‘void sciplot::Figure::cleanup() const’:
/usr/local/include/sciplot/Figure.hpp:311:27: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
  311 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::begin
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: ‘std::begin’ declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:311:27: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
  311 |     for(const auto& row : m_plots) {
      |                           ^~~~~~~
      |                           std::end
In file included from /usr/local/include/sciplot/Utils.hpp:37,
                 from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: ‘std::end’ declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Figure.hpp:313:36: error: ‘get_if’ is not a member of ‘std’
  313 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                    ^~~~~~
/usr/local/include/sciplot/Figure.hpp:313:47: error: expected primary-expression before ‘>’ token
  313 |             if(auto *plot_p = std::get_if<Plot>(&plot)) {
      |                                               ^
/usr/local/include/sciplot/Figure.hpp:315:43: error: ‘get_if’ is not a member of ‘std’
  315 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                           ^~~~~~
/usr/local/include/sciplot/Figure.hpp:315:56: error: expected primary-expression before ‘>’ token
  315 |             } else if(auto *plot_p = std::get_if<Plot3D>(&plot)) {
      |                                                        ^
In file included from /usr/local/include/sciplot/specs/FontSpecsOf.hpp:29,
                 from /usr/local/include/sciplot/specs/TextSpecsOf.hpp:30,
                 from /usr/local/include/sciplot/specs/AxisLabelSpecs.hpp:30,
                 from /usr/local/include/sciplot/PlotBase.hpp:37,
                 from /usr/local/include/sciplot/Plot.hpp:37,
                 from /usr/local/include/sciplot/Figure.hpp:33,
                 from /usr/local/include/sciplot/sciplot.hpp:32,
                 from project.cpp:2:
/usr/local/include/sciplot/Utils.hpp: In instantiation of ‘auto sciplot::internal::escapeIfNeeded(const T&) [with T = double]’:
/usr/local/include/sciplot/Utils.hpp:148:26:   required from ‘std::ostream& sciplot::internal::writeline(std::ostream&, std::size_t, const VectorType&, const Args& ...) [with VectorType = std::valarray<double>; Args = {std::_Expr<std::__detail::_UnClos<std::_Sin, std::_ValArray, double>, double>}; std::ostream = std::basic_ostream<char>; std::size_t = long unsigned int]’
/usr/local/include/sciplot/Utils.hpp:159:18:   required from ‘std::ostream& sciplot::internal::write(std::ostream&, const Args& ...) [with Args = {std::valarray<double>, std::_Expr<std::__detail::_UnClos<std::_Sin, std::_ValArray, double>, double>}; std::ostream = std::basic_ostream<char>]’
/usr/local/include/sciplot/Utils.hpp:230:20:   required from ‘std::ostream& sciplot::gnuplot::writedataset(std::ostream&, std::size_t, const Args& ...) [with Args = {std::valarray<double>, std::_Expr<std::__detail::_UnClos<std::_Sin, std::_ValArray, double>, double>}; std::ostream = std::basic_ostream<char>; std::size_t = long unsigned int]’
/usr/local/include/sciplot/Plot.hpp:480:26:   required from ‘sciplot::DrawSpecs& sciplot::Plot::drawWithVecs(const string&, const X&, const Vecs& ...) [with X = std::valarray<double>; Vecs = {std::_Expr<std::__detail::_UnClos<std::_Sin, std::_ValArray, double>, double>}; std::string = std::__cxx11::basic_string<char>]’
/usr/local/include/sciplot/Plot.hpp:525:38:   required from ‘sciplot::DrawSpecs& sciplot::Plot::drawCurve(const X&, const Y&) [with X = std::valarray<double>; Y = std::_Expr<std::__detail::_UnClos<std::_Sin, std::_ValArray, double>, double>]’
project.cpp:23:34:   required from here
/usr/local/include/sciplot/Utils.hpp:132:21: error: invalid operands of types ‘const char [2]’ and ‘const double’ to binary ‘operator+’
  132 |         return "\"" + val + "\"";
      |                ~~~~~^~~~~

Massive amount of linking errors when importing sciplot in multiple files.

Hello together,

has anyone tried to use sciplot in a larger c++ project?

Sciplot claims to be a header only library without being implemented as such.
In the headers are tons of (non template ) function definitions outside the class definition. This results in a lot of double definition errors when linking.

Also, in util.hpp all non-template functions should be declared inline.

I can submit a patch for this if you can confirm the error.

Greetings,
Julian

No parenthesis, dots, spaces in pdf file names allowed

If I do this:

plot.save("bla (abs. error).pdf");
plot.save("bla - abs. error.pdf");
plot.save("bla afterspace.pdf");

GNUplot has trouble finding the files, because the ".", "(", ")" are not escaped or removed and spaces seem to screw up saving too.

Possibility to reset a plot

Hi all,

I would like to reuse a Plot object, such that the m_drawspecs and m_customcmds are cleared and only the properties of the Plot (labels, size, palette,...) are retained. Currently, if I reuse the same plot object, all new draw... calls simply add a new set of data to the existing plot.

Of course, I could simply discard the object and create a new one each time, but since I'd like to modify its properties in separate locations of the code and independent from each other, reusing the same one would suit me better.

Is there a functionality to clear the drawspecs and command vectors (I didn't find it yet) in sciplot or would it be possible to include it?

Is c++17 really necessary?

Hi,

neat library, thanks for that!

I've only used it to draw a couples plots so far, thus I haven't 'seen it all' but I was wondering if the c++17 requirement was absolutely necessary? Beside a few constexpr if it seem that a c++14 requirement would do the job (likely even c++11).
I believe that lowering this requirement would widen the possible user base, especially since part of the target audience (researchers, students etc) may not be able to switch that flag on for various reasons.

Any thoughts?

Side question, is there any easy way to draw boxplots?

Use temporary directory or remove temporary files after show() or save()

sciplot keeps on spamming working directories with temporary files, which is not nice. It might be easiest to solve by writing all of those files to the systems temporary directory.
One possibility would be to use std::filesystem (with C++17, but support already on older compilers), which makes things cross-platform and really easy. It could be included through a header like this.

Bar graph support

I can't quite figure out how to do a bar graph (with individual texts as ticks, see here). Is there support for this and could you provide an example how to achieve this?

3D plots

Hi, is there any support for 3D plots atm? If now is it considered as a future feature?

Regards

About naming convention

I'm new to sciplot and I like it a lot.
However, the naming of the methods is kind of a surprise to me. Is there a reason for not using typical names for plotting function like plot, scatter, quiver etc?

For a while I thought these functions were not yet implemented until I went into the source code and found names like drawDots and drawPoints.

No project versioning

I'm now to the point where I'd like to bring the project into the vcpk upstream. Unfortunately I haven't found a version number anywhere. But a version number is necessary for the inclusion in a packagemanager. Does anyone already have something in mind?

library name collision

When trying to get the port into vcpkg, I was told that there is already a library called sciplot on Linux.
Since the current naming scheme causes collisions, they suggested renaming the library to allanleal-sciplot.
It should be enough to rename the cmake target (and file name) and the include directory.

I can handle that, but please give me some feedback.

Issue compiling with cmake 3.10.2

If I attempt compiling with cmake 3.10.2, which I believe is default on Ubuntu 18.04, I get the following error running cmake:

-- CCache: Could not find ccache. Install it to speed up the build operation.
CMake Error at CMakeLists.txt:7 (project):
  project with VERSION must use LANGUAGES before language names.


-- Configuring incomplete, errors occurred!

I struggled with this issue, but upgrading to cmake 3.19.6 resolved the problem. Perhaps, the cmake version should be included in the install instructions.

Int conversion Compile warning

I'm getting an int conversion compile warning when compiling the project with AppleClang 12

sciplot/sciplot/Plot.hpp:327:118: warning: implicit conversion loses integer precision: 'std::__1::vector<sciplot::DrawSpecs, std::__1::allocator<sciplot::DrawSpecs> >::size_type' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
    return draw("'" + m_datafilename + "' index " + internal::str(m_numdatasets++), use, with).lineStyle(m_drawspecs.size());

I guess this one should be easy to fix ;)

How to get value from plot ?

In the basic example:
https://sciplot.github.io/tutorials/

    Plot plot;

    // Set the width and height of the plot in points (72 points = 1 inch)
    plot.size(360, 200);

    // Set the font name and size
    plot.fontName("Palatino");
    plot.fontSize(12);

    // Set the x and y labels
    plot.xlabel("x");

How to get xlabel from C++ ?
How to get size from C++ ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.