30 #ifndef GNUPLOT_PIPES_H 31 #define GNUPLOT_PIPES_H 45 #if defined (WIN32) || defined (_WIN32) || defined (__WIN32__) || defined (__TOS_WIN__) 48 #define GP_MAX_TMP_FILES 27 // 27 temporary files it's Microsoft restriction 49 #elif defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__) 52 #define GP_MAX_TMP_FILES 64 54 #error unsupported or unknown operating system 87 std::vector<std::string> _tmpfile_list_;
90 std::string _terminal_;
95 static int _g_tmpfile_num_;
97 static std::string _g_gnuplot_filename_;
99 static std::string _g_gnuplot_path;
101 static std::string _g_terminal_std_;
120 std::string create_tmpfile (std::ofstream &tmp);
129 static bool get_program_path ();
139 bool file_available (
const std::string &filename);
149 static bool file_exists (
const std::string &filename,
int mode=0);
182 Gnuplot (
const std::string &style =
"points");
185 Gnuplot (
const std::vector<double> &x,
186 const std::string &title =
"",
187 const std::string &style =
"points",
188 const std::string &labelx =
"x",
189 const std::string &labely =
"y");
192 Gnuplot (
const std::vector<double> &x,
193 const std::vector<double> &y,
194 const std::string &title =
"",
195 const std::string &style =
"points",
196 const std::string &labelx =
"x",
197 const std::string &labely =
"y");
200 Gnuplot (
const std::vector<double> &x,
201 const std::vector<double> &y,
202 const std::vector<double> &z,
203 const std::string &title =
"",
204 const std::string &style =
"points",
205 const std::string &labelx =
"x",
206 const std::string &labely =
"y",
207 const std::string &labelz =
"z");
382 cmdstr =
"set title \"";
488 const unsigned int column = 1,
489 const std::string &title =
"");
502 std::string name = create_tmpfile(tmp);
509 for (
unsigned int i = 0; i < x.size(); i++)
510 tmp << x[i] << std::endl;
528 const unsigned int column_x = 1,
529 const unsigned int column_y = 2,
530 const std::string &title =
"");
533 const unsigned int column_x,
534 const unsigned int column_y,
535 const std::string & title,
536 const std::string & file_options_,
537 const std::string & plot_options_);
548 template<
typename X,
typename Y>
556 std::string name = create_tmpfile(tmp);
563 for (
unsigned int i = 0; i < x.size(); i++)
564 tmp << x[i] <<
" " << y[i] << std::endl;
579 const unsigned int column_x = 1,
580 const unsigned int column_y = 2,
581 const unsigned int column_dy = 3,
582 const std::string &title =
"");
593 template<
typename X,
typename Y,
typename E>
597 const std::string &title =
"")
599 DT_THROW_IF (x.size() == 0 || y.size() == 0 || dy.size() == 0,
601 DT_THROW_IF (x.size() != y.size() || y.size() != dy.size(),
604 std::string name = create_tmpfile(tmp);
611 for (
unsigned int i = 0; i < x.size(); i++)
612 tmp << x[i] <<
" " << y[i] <<
" " << dy[i] << std::endl;
627 const unsigned int column_x = 1,
628 const unsigned int column_y = 2,
629 const unsigned int column_z = 3,
630 const std::string &title =
"");
633 const unsigned int column_x = 1,
634 const unsigned int column_y = 2,
635 const unsigned int column_z = 3,
636 const unsigned int column_o = 4,
637 const std::string &title =
"");
640 const std::string &title =
"",
656 template<
typename X,
typename Y,
typename Z>
660 const std::string &title =
"")
662 DT_THROW_IF (x.size() == 0 || y.size() == 0 || z.size() == 0,
664 DT_THROW_IF (x.size() != y.size() || x.size() != z.size(),
667 std::string name = create_tmpfile(tmp);
674 for (
unsigned int i = 0; i < x.size(); i++)
675 tmp << x[i] <<
" " << y[i] <<
" " << z[i] <<std::endl;
691 const std::string &title =
"");
705 const std::string &title =
"");
710 const std::string &title =
"");
715 const unsigned int iWidth,
716 const unsigned int iHeight,
717 const std::string &title =
"");
752 #endif // GNUPLOT_PIPES_H Gnuplot(const std::string &style="points")
set a style during construction
Gnuplot & savetops(const std::string &filename="gnuplot_output")
saves a gnuplot session to a postscript file, filename without extension
Gnuplot & set_zlabel(const std::string &label="z")
set z axis label
Gnuplot & set_isosamples(const int isolines=10)
set isoline density (grid) for plotting functions as surfaces (for 3d plots)
Gnuplot & set_smooth(const std::string &stylestr="csplines")
Gnuplot & set_grid()
turns grid on/off
Definition: gnuplot_i.h:279
GnuplotException(const std::string &msg)
Gnuplot & plotfile_xy_err(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const unsigned int column_dy=3, const std::string &title="")
Gnuplot & set_ylabel(const std::string &label="x")
set x axis label
Gnuplot & set_xrange(const double iFrom, const double iTo)
set axis - ranges
Gnuplot & plot_x(const X &x, const std::string &title="")
from std::vector
Definition: gnuplot_i.h:497
Gnuplot & plotfile_xyzo(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const unsigned int column_z=3, const unsigned int column_o=4, const std::string &title="")
static bool set_gnuplot_path(const std::string &path)
optional function: set Gnuplot path manual attention: for windows: path with slash '/' not backslash ...
Gnuplot & set_yautoscale()
Definition: gnuplot_i.h:431
Gnuplot & set_multiplot()
Definition: gnuplot_i.h:290
Gnuplot & set_surface()
Definition: gnuplot_i.h:345
Gnuplot & set_hidden3d()
Definition: gnuplot_i.h:315
Gnuplot & unset_contour()
Definition: gnuplot_i.h:336
void remove_tmpfiles()
deletes temporary files
Gnuplot & reset_plot()
resets a gnuplot session (next plot will erase previous ones)
Gnuplot & set_xlabel(const std::string &label="y")
set y axis label
const std::string & get_terminal() const
Return the active terminal type.
Gnuplot & set_ylogscale(const double base=10)
turns on/off log scaling for the specified yaxis (logscale is not set by default)
Gnuplot & set_xautoscale()
Definition: gnuplot_i.h:422
Gnuplot & plotfile_xyz(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const unsigned int column_z=3, const std::string &title="")
Definition: gnuplot_i.h:68
Gnuplot & unset_multiplot()
Definition: gnuplot_i.h:299
Gnuplot & set_zautoscale()
Definition: gnuplot_i.h:440
Utility macros for exception handling.
Gnuplot & set_legend(const std::string &position="default")
Gnuplot & set_zlogscale(const double base=10)
turns on/off log scaling for the specified zaxis (logscale is not set by default)
Gnuplot & unset_surface()
Definition: gnuplot_i.h:355
Gnuplot & unset_zlogscale()
Definition: gnuplot_i.h:475
Gnuplot & set_title(const std::string &title="")
sets and clears the title of a gnuplot session
Definition: gnuplot_i.h:379
Gnuplot & set_yrange(const double iFrom, const double iTo)
set y-axis - ranges
Gnuplot & plotfile_xyz_with_colored_wires(const std::string &filename, const std::string &title="", int color_=0)
Gnuplot & plot_equation3d(const std::string &equation, const std::string &title="")
void set_terminal(const std::string &terminal_)
Set the active terminal.
bool has_terminal() const
Check if terminal is set.
Gnuplot & unset_title()
Clears the title of a gnuplot session The title is not set by default.
Definition: gnuplot_i.h:397
Gnuplot & replot(void)
replot repeats the last plot or splot command. this can be useful for viewing a plot with different s...
Definition: gnuplot_i.h:729
Gnuplot & set_cbrange(const double iFrom, const double iTo)
set palette range (autoscale by default)
Gnuplot & unset_hidden3d()
Definition: gnuplot_i.h:324
Gnuplot & plot_xy_err(const X &x, const Y &y, const E &dy, const std::string &title="")
from data
Definition: gnuplot_i.h:594
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76
Gnuplot & set_samples(const int samples=100)
set sampling rate of functions, or for interpolating data
static const std::string & terminal_std()
Return the default terminal type on the current system.
Gnuplot & operator<<(const std::string &cmdstr)
Sends a command to an active gnuplot session, identical to cmd () send a command to gnuplot using the...
Definition: gnuplot_i.h:233
Gnuplot & plot_xy(const X &x, const Y &y, const std::string &title="")
from data
Definition: gnuplot_i.h:549
Gnuplot & unset_legend()
Switches legend off attention:legend is set by default.
Definition: gnuplot_i.h:370
Gnuplot & set_style(const std::string &stylestr="points")
Gnuplot & plotfile_xy(const std::string &filename, const unsigned int column_x=1, const unsigned int column_y=2, const std::string &title="")
Gnuplot & plot_xyz(const X &x, const Y &y, const Z &z, const std::string &title="")
from std::vector
Definition: gnuplot_i.h:657
static void set_terminal_std(const std::string &type)
Gnuplot & plotfile_x(const std::string &filename, const unsigned int column=1, const std::string &title="")
Gnuplot & unset_smooth()
unset smooth attention: smooth is not set by default
Definition: gnuplot_i.h:272
Gnuplot & set_pointsize(const double pointsize=1.0)
scales the size of the points used in plots
Gnuplot & set_xlogscale(const double base=10)
turns on/off log scaling for the specified xaxis (logscale is not set by default)
Gnuplot & cmd(const std::string &cmdstr)
send a command to gnuplot
Gnuplot & set_zrange(const double iFrom, const double iTo)
set z-axis - ranges
Gnuplot & unset_ylogscale()
Definition: gnuplot_i.h:466
Gnuplot & plot_slope(const double a, const double b, const std::string &title="")
plot an equation of the form: y = ax + b, you supply a and b
Definition: gnuplot_i.h:61
bool is_valid()
Is the gnuplot session valid ??
Definition: gnuplot_i.h:748
Gnuplot & plot_image(const unsigned char *ucPicBuf, const unsigned int iWidth, const unsigned int iHeight, const std::string &title="")
plot image
~Gnuplot()
destructor: needed to delete temporary files
Gnuplot & set_contour(const std::string &position="base")
Gnuplot & unset_grid()
grid is not set by default
Definition: gnuplot_i.h:281
Gnuplot & unset_xlogscale()
Definition: gnuplot_i.h:457
Gnuplot & reset_all()
resets a gnuplot session and sets all variables to default
Gnuplot & plot_equation(const std::string &equation, const std::string &title="")