diff --git a/axis.cpp b/axis.cpp index 287955a..0d32263 100644 --- a/axis.cpp +++ b/axis.cpp @@ -533,6 +533,14 @@ void pgfplotter::Axis::matrix(const std::vector& x, const std::vector< matrixSurf.push_back(true); } +void pgfplotter::Axis::fill(const std::array& color, const std::vector< + double>& x, const std::vector& y) +{ + fillX.push_back(x); + fillY.push_back(y); + fillColors.push_back(color); +} + void pgfplotter::Axis::legend(unsigned int location) { legendPos = location; @@ -1147,6 +1155,33 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con } } + for(std::size_t i = 0; i < fillX.size(); ++i) + { + const std::size_t numPoints = fillX[i].size(); + if(fillY[i].size() != numPoints) + { + throw std::runtime_error("Number of points in x and y must match."); + } + src += "\\fill["; + if(fillColors[i][0] >= 0) + { + src += "rgb color = {" + std::to_string(fillColors[i][0]) + ", " + + std::to_string(fillColors[i][1]) + ", " + std::to_string( + fillColors[i][2]) + "}"; + } + else + { + src += "black"; + } + src += "] "; + for(std::size_t j = 0; j < numPoints; ++j) + { + src += "(" + ToString(fillX[i][j]) + ", " + ToString(fillY[i][j]) + + ")--"; + } + src += "cycle;" + endl; + } + for(std::size_t i = 0, sz = data.size(); i < sz; ++i) { const std::size_t numPoints = data[i][0].size(); diff --git a/pgfplotter b/pgfplotter index b8e787d..f8354f3 100644 --- a/pgfplotter +++ b/pgfplotter @@ -136,6 +136,9 @@ namespace pgfplotter std::vector lineStyles; std::vector lineWidths; std::vector opacities; + std::vector> fillX; + std::vector> fillY; + std::vector> fillColors; std::array _viewAngles = {0., 90.}; @@ -227,6 +230,9 @@ namespace pgfplotter void matrix(const std::vector& x, const std::vector& y, const std::vector& z, const std::string& name = ""); + void fill(const std::array& color, const std::vector& x, + const std::vector& y); + void legend(unsigned int location = Northeast); void squeeze(); void squeezeX();