diff --git a/lib/Core/Plot.cpp b/lib/Core/Plot.cpp index b36e19c..c2758a3 100644 --- a/lib/Core/Plot.cpp +++ b/lib/Core/Plot.cpp @@ -261,6 +261,27 @@ PlotHistogram::PlotHistogram(const Histogram &h) setCommand("'" + tmpFileName + "' u 1:2 w steps"); } +// PlotImpulses constructor //////////////////////////////////////////////////// +PlotImpulses::PlotImpulses(const DVec &x, const DVec &y) +{ + if (x.rows() != y.rows()) + { + LATAN_ERROR(Size, "x and y vector does not have the same size"); + } + + DMat d(x.rows(), 2); + string tmpFileName; + + for (Index i = 0; i < x.rows(); ++i) + { + d(i, 0) = x(i); + d(i, 1) = y(i); + } + tmpFileName = dumpToTmpFile(d); + pushTmpFile(tmpFileName); + setCommand("'" + tmpFileName + "' u 1:2 w impulses"); +} + // PlotMatrixNoRange constructor /////////////////////////////////////////////// PlotMatrixNoRange::PlotMatrixNoRange(const DMat &m) { @@ -371,6 +392,31 @@ void Title::operator()(PlotOptions &option) const option.title = title_; } +// Palette constructor ///////////////////////////////////////////////////////// +Palette::Palette(const std::vector &palette) +: palette_(palette) +{} + +// Palette modifier //////////////////////////////////////////////////////////// +void Palette::operator()(PlotOptions &option) const +{ + option.palette = palette_; +} + +// category10 palette ////////////////////////////////////////////////////////// +const std::vector Palette::category10 = +{ + "rgb '#1f77b4'", + "rgb '#ff7f0e'", + "rgb '#2ca02c'", + "rgb '#d62728'", + "rgb '#9467bd'", + "rgb '#8c564b'", + "rgb '#e377c2'", + "rgb '#7f7f7f'", + "rgb '#bcbd22'" +}; + /****************************************************************************** * Plot implementation * ******************************************************************************/ @@ -394,6 +440,7 @@ void Plot::initOptions(void) options_.label[0] = ""; options_.label[1] = ""; options_.lineColor = ""; + options_.palette = Palette::category10; } // plot reset ////////////////////////////////////////////////////////////////// @@ -674,6 +721,11 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot) { out << "set ylabel '" << plot.options_.label[y] << "'" << endl; } + for (unsigned int i = 0; i < plot.options_.palette.size(); ++i) + { + out << "set linetype " << i + 1 << " lc " + << plot.options_.palette[i] << endl; + } for (unsigned int i = 0; i < plot.headCommand_.size(); ++i) { out << plot.headCommand_[i] << endl; diff --git a/lib/Core/Plot.hpp b/lib/Core/Plot.hpp index 7db96ac..f3b8508 100644 --- a/lib/Core/Plot.hpp +++ b/lib/Core/Plot.hpp @@ -146,6 +146,15 @@ public: virtual ~PlotHistogram(void) = default; }; +class PlotImpulses: public PlotObject +{ +public: + // constructor + PlotImpulses(const DVec &x, const DVec &y); + // destructor + virtual ~PlotImpulses(void) = default; +}; + class PlotMatrixNoRange: public PlotObject { public: @@ -172,14 +181,15 @@ struct Range struct PlotOptions { - std::string terminal; - std::string output; - std::string caption; - std::string title; - unsigned int scaleMode[2]; - Range scale[2]; - std::string label[2]; - std::string lineColor; + std::string terminal; + std::string output; + std::string caption; + std::string title; + unsigned int scaleMode[2]; + Range scale[2]; + std::string label[2]; + std::string lineColor; + std::vector palette; }; class PlotModifier @@ -286,6 +296,21 @@ private: const std::string title_; }; +class Palette: public PlotModifier +{ +public: + static const std::vector category10; +public: + // constructor + explicit Palette(const std::vector &palette); + // destructor + virtual ~Palette(void) = default; + // modifier + virtual void operator()(PlotOptions &option) const; +private: + const std::vector palette_; +}; + /****************************************************************************** * Plot class * ******************************************************************************/ diff --git a/lib/Functional/Function.cpp b/lib/Functional/Function.cpp index 3216fbe..f83fef2 100644 --- a/lib/Functional/Function.cpp +++ b/lib/Functional/Function.cpp @@ -111,6 +111,20 @@ double DoubleFunction::operator()(void) const return (*this)(nullptr); } +std::map DoubleFunction::operator()(const std::map &m) const +{ + checkSize(1); + + std::map res; + + for (auto &val: m) + { + res[val.first] = (*this)(val.second); + } + + return res; +} + // bind //////////////////////////////////////////////////////////////////////// DoubleFunction DoubleFunction::bind(const Index argIndex, const double val) const diff --git a/lib/Functional/Function.hpp b/lib/Functional/Function.hpp index 724d61e..2afdda7 100644 --- a/lib/Functional/Function.hpp +++ b/lib/Functional/Function.hpp @@ -52,6 +52,7 @@ public: double operator()(void) const; template double operator()(const double arg0, const Ts... args) const; + std::map operator()(const std::map &m) const; // bind DoubleFunction bind(const Index argIndex, const double val) const; DoubleFunction bind(const Index argIndex, const DVec &x) const;