diff --git a/plotter.cpp b/axis.cpp similarity index 79% rename from plotter.cpp rename to axis.cpp index f6e9a06..c72b6f6 100644 --- a/plotter.cpp +++ b/axis.cpp @@ -153,6 +153,10 @@ static const std::string Suffix = "_plot_data"; static std::string convert_marker(char marker) { + if(!marker) + { + return "none"; + } if(marker == '^') { return "triangle"; @@ -173,7 +177,7 @@ static std::string convert_marker(char marker) static const std::string endl = "\n"; // Convert numbers to strings without sacrificing precision. -std::string pgfplotter::Plotter::ToString(double x, unsigned int precision) +std::string pgfplotter::Axis::ToString(double x, unsigned int precision) { std::stringstream ss; ss << std::setprecision(precision) << x; @@ -423,163 +427,47 @@ static const std::string src4 = "\\end{groupplot}" + endl + static const std::string src5 = "\\end{document}"; static const std::string src7 = "" + endl; -void pgfplotter::Plotter::setTitle(const std::string& title) +void pgfplotter::Axis::setTitle(const std::string& title) { _title = title; } -void pgfplotter::Plotter::setXLabel(const std::string& xLabel) +void pgfplotter::Axis::setXLabel(const std::string& xLabel) { _xLabel = xLabel; } -void pgfplotter::Plotter::setYLabel(const std::string& yLabel) +void pgfplotter::Axis::setYLabel(const std::string& yLabel) { _yLabel = yLabel; } -void pgfplotter::Plotter::setZLabel(const std::string& zLabel) +void pgfplotter::Axis::setZLabel(const std::string& zLabel) { _zLabel = zLabel; } -void pgfplotter::Plotter::line(const std::vector& x, const std::vector& y, - const std::vector& z, const std::string& name, const std::array& color, double width) -{ - data.push_back({x, y, z}); - markers.emplace_back(); - names.push_back(name); - colors.push_back(color); - lineStyles.push_back(0); - lineWidths.push_back(width); - opacities.push_back(1.); -} - -void pgfplotter::Plotter::dashed(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color) +void pgfplotter::Axis::setWLabel(const std::string& wLabel) { - data.push_back({x, y, {}}); - markers.emplace_back(); - names.push_back(name); - colors.push_back(color); - lineStyles.push_back(1); - lineWidths.push_back(1.); - opacities.push_back(1.); + setZLabel(wLabel); //TEMP - separate z & w } -void pgfplotter::Plotter::dotted(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color) +void pgfplotter::Axis::draw(const DrawStyle& style, const std::vector& + x, const std::vector& y, const std::vector& z, const std:: + vector& w, const std::string& name) { - data.push_back({x, y, {}}); - markers.emplace_back(); + data.push_back({x, y, z, w}); + markers.emplace_back(convert_marker(style.markStyle.mark), style.markStyle. + size, style.markStyle.spacing); names.push_back(name); - colors.push_back(color); - lineStyles.push_back(2); - lineWidths.push_back(1.); - opacities.push_back(1.); + colors.push_back(style.color); + lineStyles.push_back(style.lineStyle); + lineWidths.push_back(style.lineWidth); + opacities.push_back(style.opacity); } -void pgfplotter::Plotter::scatter(const std::vector& x, const std::vector& - y, const std::vector& z, char marker, const std::string& name, const - std::array& color, double opacity) -{ - data.push_back({x, y, z}); - markers.push_back(convert_marker(marker)); - names.push_back(name); - colors.push_back(color); - lineStyles.push_back(0); - lineWidths.push_back(1.); - opacities.push_back(opacity); -} - -void pgfplotter::Plotter::polar_line(const std::vector& r, const std::vector< - double>& theta, const std::string& name, const std::array& color) -{ - const std::size_t n = theta.size(); - std::vector x(n); - std::vector y(n); - for(std::size_t i = 0; i < n; ++i) - { - x[i] = r[i]*std::cos(theta[i]); - y[i] = r[i]*std::sin(theta[i]); - } - data.push_back({x, y, {}}); - markers.emplace_back(); - names.push_back(name); - colors.push_back(color); - lineStyles.push_back(0); - lineWidths.push_back(1.); - opacities.push_back(1.); -} - -void pgfplotter::Plotter::polar_scatter(const std::vector& r, const std::vector< - double>& theta, char marker, const std::string& name, const std::array& color) -{ - const std::size_t n = theta.size(); - std::vector x(n); - std::vector y(n); - for(std::size_t i = 0; i < n; ++i) - { - x[i] = r[i]*std::cos(theta[i]); - y[i] = r[i]*std::sin(theta[i]); - } - data.push_back({x, y, {}}); - markers.push_back(convert_marker(marker)); - names.push_back(name); - colors.push_back(color); - lineStyles.push_back(0); - lineWidths.push_back(1.); - opacities.push_back(1.); -} - -void pgfplotter::Plotter::stairs(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color) -{ - const std::size_t n = x.size(); - std::vector x1(2*n); - std::vector y1(2*n); - y1[0] = y[0]; - for(std::size_t i = 0; i + 1 < n; ++i) - { - y1[2*i + 1] = y[i]; - y1[2*i + 2] = y[i]; - } - y1[2*n - 1] = y[n - 1]; - for(std::size_t i = 0; i < n; ++i) - { - x1[2*i] = x[i]; - x1[2*i + 1] = x[i]; - } - - line(x1, y1, name, color); -} - -void pgfplotter::Plotter::dashed_stairs(const std::vector& x, const std::vector< - double>& y, const std::string& name, const std::array& color) -{ - const std::size_t n = x.size(); - std::vector x1(2*n); - std::vector y1(2*n); - y1[0] = y[0]; - for(std::size_t i = 0; i + 1 < n; ++i) - { - y1[2*i + 1] = y[i]; - y1[2*i + 2] = y[i]; - } - y1[2*n - 1] = y[n - 1]; - for(std::size_t i = 0; i < n; ++i) - { - x1[2*i] = x[i]; - x1[2*i + 1] = x[i]; - } - - dashed(x1, y1, name, color); -} - -void pgfplotter::Plotter::surf(const std::vector& x, const std::vector& y, - const std::vector& z, const std::string& name) +void pgfplotter::Axis::surf(const std::vector& x, const std::vector< + double>& y, const std::vector& z, const std::string& name) { surfaceX.push_back(x); surfaceY.push_back(y); @@ -589,9 +477,9 @@ void pgfplotter::Plotter::surf(const std::vector& x, const std::vector& x, const std::vector& - y, const std::vector& z, unsigned int contours, const std::string& - name) +void pgfplotter::Axis::contour(const std::vector& x, const std::vector< + double>& y, const std::vector& z, unsigned int contours, const std:: + string& name) { surfaceX.push_back(x); surfaceY.push_back(y); @@ -601,8 +489,8 @@ void pgfplotter::Plotter::contour(const std::vector& x, const std::vecto matrixSurf.push_back(false); } -void pgfplotter::Plotter::matrix(const std::vector& x, const std::vector& y, - const std::vector& z, const std::string& name) +void pgfplotter::Axis::matrix(const std::vector& x, const std::vector< + double>& y, const std::vector& z, const std::string& name) { surfaceX.push_back(x); surfaceY.push_back(y); @@ -612,96 +500,96 @@ void pgfplotter::Plotter::matrix(const std::vector& x, const std::vector matrixSurf.push_back(true); } -//TEMP -void pgfplotter::Plotter::circles(const std::vector& x, const std::vector& - y, const std::vector& r) -{ - circleX.insert(circleX.end(), x.begin(), x.end()); - circleY.insert(circleY.end(), y.begin(), y.end()); - circleR.insert(circleR.end(), r.begin(), r.end()); -} -//TEMP - -void pgfplotter::Plotter::legend(unsigned int location) +void pgfplotter::Axis::legend(unsigned int location) { legendPos = location; } -void pgfplotter::Plotter::squeeze() +void pgfplotter::Axis::squeeze() { xSqueeze = true; ySqueeze = true; } -void pgfplotter::Plotter::squeeze_x() +void pgfplotter::Axis::squeeze_x() { xSqueeze = true; } -void pgfplotter::Plotter::squeeze_y() +void pgfplotter::Axis::squeeze_y() { ySqueeze = true; } -void pgfplotter::Plotter::x_min(double x) +void pgfplotter::Axis::setXMin(double x) { xMinSet = true; xMin = x; } -void pgfplotter::Plotter::x_max(double x) +void pgfplotter::Axis::setXMax(double x) { xMaxSet = true; xMax = x; } -void pgfplotter::Plotter::y_min(double y) +void pgfplotter::Axis::setYMin(double y) { yMinSet = true; yMin = y; } -void pgfplotter::Plotter::y_max(double y) +void pgfplotter::Axis::setYMax(double y) { yMaxSet = true; yMax = y; } -void pgfplotter::Plotter::z_min(double z) +void pgfplotter::Axis::setZMin(double z) { zMinSet = true; zMin = z; } -void pgfplotter::Plotter::z_max(double z) +void pgfplotter::Axis::setZMax(double z) { zMaxSet = true; zMax = z; } -void pgfplotter::Plotter::axis_equal() +void pgfplotter::Axis::setWMin(double w) +{ + setZMin(w); //TEMP - separate z & w +} + +void pgfplotter::Axis::setWMax(double w) +{ + setZMax(w); //TEMP - separate z & w +} + +void pgfplotter::Axis::axis_equal() { axisEqual = true; } -void pgfplotter::Plotter::axis_equal_image() +void pgfplotter::Axis::axis_equal_image() { axisEqualImage = true; } -void pgfplotter::Plotter::resize(double width, double height) +void pgfplotter::Axis::resize(double width, double height) { relWidth = width; relHeight = height; } -void pgfplotter::Plotter::resize(double size) +void pgfplotter::Axis::resize(double size) { relWidth = size; relHeight = size; } -void pgfplotter::Plotter::x_precision(int n) +void pgfplotter::Axis::setXPrecision(int n) { if(n < 0) { @@ -710,7 +598,7 @@ void pgfplotter::Plotter::x_precision(int n) xPrecision = n; } -void pgfplotter::Plotter::y_precision(int n) +void pgfplotter::Axis::setYPrecision(int n) { if(n < 0) { @@ -719,7 +607,7 @@ void pgfplotter::Plotter::y_precision(int n) yPrecision = n; } -void pgfplotter::Plotter::z_precision(int n) +void pgfplotter::Axis::setZPrecision(int n) { if(n < 0) { @@ -728,77 +616,87 @@ void pgfplotter::Plotter::z_precision(int n) zPrecision = n; } -void pgfplotter::Plotter::x_format(unsigned int mode) +void pgfplotter::Axis::setWPrecision(int n) +{ + setZPrecision(n); //TEMP - separate z & w +} + +void pgfplotter::Axis::setXFormat(unsigned int mode) { xFormat = mode; } -void pgfplotter::Plotter::y_format(unsigned int mode) +void pgfplotter::Axis::setYFormat(unsigned int mode) { yFormat = mode; } -void pgfplotter::Plotter::z_format(unsigned int mode) +void pgfplotter::Axis::setZFormat(unsigned int mode) { zFormat = mode; } -void pgfplotter::Plotter::x_log() +void pgfplotter::Axis::setWFormat(unsigned int mode) +{ + zFormat = mode; //TEMP - separate z & w +} + +void pgfplotter::Axis::x_log() { xLog = true; } -void pgfplotter::Plotter::y_log() +void pgfplotter::Axis::y_log() { yLog = true; } -void pgfplotter::Plotter::z_log() +void pgfplotter::Axis::z_log() { zLog = true; } -void pgfplotter::Plotter::colorbar() +void pgfplotter::Axis::showColorbar() { - showColorbar = true; + _showColorbar = true; } -void pgfplotter::Plotter::scale_x_spacing(double n) +void pgfplotter::Axis::scale_x_spacing(double n) { xSpacing = n; } -void pgfplotter::Plotter::scale_y_spacing(double n) +void pgfplotter::Axis::scale_y_spacing(double n) { ySpacing = n; } -void pgfplotter::Plotter::scale_z_spacing(double n) +void pgfplotter::Axis::scale_z_spacing(double n) { zSpacing = n; } -void pgfplotter::Plotter::x_offset(double n) +void pgfplotter::Axis::x_offset(double n) { xOffset = n; } -void pgfplotter::Plotter::view(double a, double b) +void pgfplotter::Axis::setView(double az, double el) { - viewAngles = {a, b}; + _viewAngles = {az, el}; } -void pgfplotter::Plotter::opacity(double n) +void pgfplotter::Axis::opacity(double n) { _opacity = n; } -void pgfplotter::Plotter::noSep() +void pgfplotter::Axis::noSep() { _noSep = true; } -void pgfplotter::Plotter::xTicks(const std::vector& locations, const std::vector< +void pgfplotter::Axis::xTicks(const std::vector& locations, const std::vector< std::string>& labels, bool rotate) { _xTicks = locations; @@ -806,17 +704,17 @@ void pgfplotter::Plotter::xTicks(const std::vector& locations, const std _rotateXTickLabels = rotate; } -void pgfplotter::Plotter::bgBands(const std::vector& transitions) +void pgfplotter::Axis::bgBands(const std::vector& transitions) { _bgBands = transitions; } -void pgfplotter::Plotter::bidirColormap() +void pgfplotter::Axis::bidirColormap() { _bidirColormap = true; } -std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) const +std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) const { if(path.empty()) { @@ -855,9 +753,9 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) "= "; src += _bidirColormap ? "bidir" : "viridis"; src += ", every axis plot/.append style = {ultra thick}, view = {" + - ToString(viewAngles[0]) + "}{" + ToString(viewAngles[1]) + "}, clip mod" - "e = individual, colorbar style = {font = \\" + FontSize + ", y tick la" - "bel style = {"; + ToString(_viewAngles[0]) + "}{" + ToString(_viewAngles[1]) + "}, clip m" + "ode = individual, colorbar style = {font = \\" + FontSize + ", y tick " + "label style = {"; if(zPrecision >= 0) { src += ", /pgf/number format/precision = " + ToString(zPrecision) + @@ -921,7 +819,7 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) "res{\\pgfmathresult*" + ToString(zSpacing) + "}}"; } - if(showColorbar) + if(_showColorbar) { src += ", colorbar"; } @@ -987,7 +885,7 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) // Z/meta max/min don't seem to affect contour placement in contour plots. if(zMinSet) { - if(viewAngles[0] != 0. || viewAngles[1] != 90.) + if(_viewAngles[0] != 0. || _viewAngles[1] != 90.) { src += ", zmin = " + ToString(zMin); } @@ -995,7 +893,7 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) } if(zMaxSet) { - if(viewAngles[0] != 0. || viewAngles[1] != 90.) + if(_viewAngles[0] != 0. || _viewAngles[1] != 90.) { src += ", zmax = " + ToString(zMax); } @@ -1058,7 +956,7 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) src += ", axis equal image"; } src += src1; - if(!viewAngles[0] && !viewAngles[1]) + if(!_viewAngles[0] && !_viewAngles[1]) { src += ", xlabel near ticks, ylabel near ticks"; } @@ -1168,8 +1066,8 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) const std::size_t numPoints = surfaceX[i].size(); if(surfaceY[i].size() != numPoints || surfaceZ[i].size() != numPoints) { - throw std::runtime_error("Number of points in x, y and z must match" - "."); + throw std::runtime_error("Number of points in x, y, and z must matc" + "h."); } std::size_t numRows = 1; @@ -1231,6 +1129,7 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) { const std::size_t numPoints = data[i][0].size(); const bool is3D = !data[i][2].empty(); + const bool hasMeta = !data[i][3].empty(); if(data[i][1].size() != numPoints) { throw std::runtime_error("Number of points in x and y must match."); @@ -1239,34 +1138,47 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) { throw std::runtime_error("Number of points in x and z must match."); } + if(hasMeta && data[i][3].size() != numPoints) + { + throw std::runtime_error("Number of points in x and w must match."); + } + + const bool hasLines = lineStyles[i] != LineStyle::None; + const bool hasMarks = std::get<0>(markers[i]) != "none"; src += is3D ? "\\addplot3+[" : "\\addplot+["; - if(lineStyles[i] == 1) + if(lineStyles[i] == LineStyle::Dashed) { src += "densely dashed, "; } - else if(lineStyles[i] == 2) + else if(lineStyles[i] == LineStyle::Dotted) { src += "densely dotted, "; } - /*if(names[i].empty()) + else if(lineStyles[i] == LineStyle::None) { - src += "forget plot, "; - }*/ - if(!markers[i].empty()) - { - src += "mark = " + markers[i] + ", mark size = 3, only marks"; - } - else - { - src += "mark = none"; + src += "only marks, "; } + src += "mark = " + std::get<0>(markers[i]) + ", mark size = " + + ToString(3.*std::get<1>(markers[i])); if(colors[i][0] >= 0) { src += ", rgb color = {" + std::to_string(colors[i][0]) + ", " + std::to_string(colors[i][1]) + ", " + std::to_string(colors[i][ 2]) + "}"; } + else if(colors[i][0] == Color::FromW[0]) + { + if(hasLines) + { + src += ", mesh, point meta = explicit, shader = interp"; + } + if(hasMarks) + { + src += ", scatter, scatter src = explicit, scatter/use mapped c" + "olor = {draw = mapped color, fill = mapped color}"; + } + } src += ", fill opacity = " + std::to_string(opacities[i]) + ", draw opacity = " + std::to_string(opacities[i]); if(lineWidths[i] != 1.) @@ -1275,7 +1187,8 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) } const std::string dataFile = std::to_string(subplot) + "." + std:: to_string(i) + ".data"; - src += "] table {" + dataFile + src3; + src += "] table" + std::string(hasMeta ? "[meta = w]" : "") + " {" + + dataFile + src3; const std::string dataPath = path + Suffix + "/" + dataFile; std::ofstream out(dataPath); if(!out) @@ -1283,11 +1196,13 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) throw std::runtime_error("Failed to open temporary output file \"" + dataPath + "\"."); } - out << "x y" << (is3D ? " z" : "") << std::endl; + out << "x y" << (is3D ? " z" : "") << (hasMeta ? " w" : "") << std:: + endl; for(std::size_t j = 0; j < numPoints; ++j) { out << ToString(data[i][0][j]) << " " << ToString(data[i][1][j]) << - (is3D ? " " + ToString(data[i][2][j]) : "") << std::endl; + (is3D ? " " + ToString(data[i][2][j]) : "") << (hasMeta ? " " + + ToString(data[i][3][j]) : "") << std::endl; } } @@ -1304,20 +1219,11 @@ std::string pgfplotter::Plotter::plot_src(const std::string& path, int subplot) src += "}" + endl; } - //TEMP - for(std::size_t i = 0; i < circleX.size(); ++i) - { - src += "\\draw (axis cs:" + ToString(circleX[i]) + ", " + ToString( - circleY[i]) + ") circle [radius = " + ToString(circleR[i]) + "];" + - endl; - } - //TEMP - return src; } void pgfplotter::plot(const std::string& path, const std::vector& p) + pgfplotter::Axis*>& p) { if(p.empty()) { diff --git a/pgfplotter b/pgfplotter index b1a3f60..e381f2a 100644 --- a/pgfplotter +++ b/pgfplotter @@ -20,44 +20,101 @@ namespace pgfplotter double, double)>& f, double xMin, double xMax, double yMin, double yMax, std::size_t xRes, std::size_t yRes); - class Plotter + namespace Color { - friend void plot(const std::string&, const std::vector&); - - static constexpr std::array, 5> _colorCycle = {{ + // These have uniformly increasing perceived lightness. + static constexpr std::array, 5> Defaults = + {{ { 0, 57, 181}, {202, 46, 0}, { 44, 151, 225}, {141, 202, 58}, {255, 227, 0} }}; + // Blue to white to red, with equal perceived lightness and saturation + // at both ends. + static constexpr std::array, 3> Bidir = + {{ + { 10, 10, 143}, + {255, 255, 255}, + {160, 10, 10} + }}; + static constexpr std::array Black = {}; + static constexpr std::array DarkGray = {64, 64, 64}; + static constexpr std::array Gray = {128, 128, 128}; + static constexpr std::array LightGray = {191, 191, 191}; + static constexpr std::array White = {255, 255, 255}; + static constexpr std::array Red = {255, 0, 0}; + static constexpr std::array Green = {0, 255, 0}; + static constexpr std::array Blue = {0, 0, 255}; + // Selects color from `Defaults`. + static constexpr std::array Auto = {-1}; + static constexpr std::array FromX = {-2}; + static constexpr std::array FromY = {-3}; + static constexpr std::array FromZ = {-4}; + static constexpr std::array FromW = {-5}; + } + + enum class LineStyle + { + Solid, Dashed, Dotted, None + }; + + struct MarkStyle + { + char mark; + double size; + int spacing; + static constexpr MarkStyle Default() + { + return {'.', 1., 1}; + } + static constexpr MarkStyle None() + { + return {}; + } + static constexpr MarkStyle Auto() + { + return {-1, 0., 0}; + } + }; + + struct DrawStyle + { + std::array color; + MarkStyle markStyle; + LineStyle lineStyle; + double lineWidth; + double opacity; + }; + static constexpr DrawStyle DefaultLine = {Color::Auto, MarkStyle::None(), + LineStyle::Solid, 1., 1.}; + static constexpr DrawStyle DefaultScatter = {Color::Auto, MarkStyle:: + Default(), LineStyle::None, 1., 1.}; + + class Axis + { + friend void plot(const std::string&, const std::vector&); std::string _title; std::string _xLabel; std::string _yLabel; std::string _zLabel; - std::vector, 3>> data; + std::vector, 4>> data; std::vector> surfaceX; std::vector> surfaceY; std::vector> surfaceZ; std::vector matrixSurf; std::vector numContours; std::vector names; - std::vector markers; + std::vector> markers; std::vector> colors; - std::vector lineStyles; + std::vector lineStyles; std::vector lineWidths; std::vector opacities; - //TEMP - std::vector circleX; - std::vector circleY; - std::vector circleR; - //TEMP - - std::array viewAngles = {0.0, 90.0}; + std::array _viewAngles = {0.0, 90.0}; double _opacity = 1.0; // Should be per-surface (like `surfaceX`, etc.). @@ -98,7 +155,7 @@ namespace pgfplotter bool yLog = false; bool zLog = false; - bool showColorbar = false; + bool _showColorbar = false; double xSpacing = 0.0; double ySpacing = 0.0; @@ -121,19 +178,11 @@ namespace pgfplotter public: static constexpr std::array ColorCycle(std::size_t i) { - return _colorCycle[i%_colorCycle.size()]; + return Color::Defaults[i%Color::Defaults.size()]; } static std::string ToString(double x, unsigned int precision = 10); - static constexpr std::array Black = {}; - static constexpr std::array DarkGray = {64, 64, 64}; - static constexpr std::array Gray = {128, 128, 128}; - static constexpr std::array LightGray = {191, 191, 191}; - static constexpr std::array Red = {255, 0, 0}; - static constexpr std::array Green = {0, 255, 0}; - static constexpr std::array Blue = {0, 0, 255}; - static constexpr std::array AutoColor = {-1, -1, -1}; static constexpr unsigned int Fixed = 1; static constexpr unsigned int Sci = 2; static constexpr unsigned int Northeast = 3; @@ -145,326 +194,54 @@ namespace pgfplotter void setXLabel(const std::string& xLabel); void setYLabel(const std::string& yLabel); void setZLabel(const std::string& zLabel); + void setWLabel(const std::string& zLabel); - void line(const std::vector& x, const std::vector& y, - const std::vector& z, const std::string& name, const std:: - array& color, double width); - void line(const std::vector& x, const std::vector& y, - const std::vector& z, const std::array& color) - { - line(x, y, z, "", color, 1.); - } - void line(const std::vector& x, const std::vector& y, const - std::vector& z, const std::string& name) - { - line(x, y, z, name, AutoColor, 1.); - } - void line(const std::vector& x, const std::vector& y, const - std::vector& z) - { - line(x, y, z, "", AutoColor, 1.); - } - void line(const std::vector& x, const std::vector& y, const - std::string& name, const std::array& color, double width) - { - line(x, y, {}, name, color, width); - } - void line(const std::vector& x, const std::vector& y, const - std::string& name, const std::array& color) - { - line(x, y, {}, name, color, 1.); - } - void line(const std::vector& x, const std::vector& y, const - std::array& color) - { - line(x, y, {}, "", color, 1.); - } - void line(const std::vector& x, const std::vector& y, const - std::string& name) - { - line(x, y, {}, name, AutoColor, 1.); - } - void line(const std::vector& x, const std::vector& y) - { - line(x, y, {}, "", AutoColor, 1.); - } - // ... - - void dashed(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color); - void dashed(const std::vector& x, const std::vector& y, - const std::array& color) - { - dashed(x, y, "", color); - } - void dashed(const std::vector& x, const std::vector& y, - const std::string& name) - { - dashed(x, y, name, AutoColor); - } - void dashed(const std::vector& x, const std::vector& y) - { - dashed(x, y, "", AutoColor); - } - - void dotted(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color); - void dotted(const std::vector& x, const std::vector& y, - const std::array& color) - { - dotted(x, y, "", color); - } - void dotted(const std::vector& x, const std::vector& y, - const std::string& name) - { - dotted(x, y, name, AutoColor); - } - void dotted(const std::vector& x, const std::vector& y) - { - dotted(x, y, "", AutoColor); - } + // Either `z` (height) or `w` (meta) or both may be left empty. + void draw(const DrawStyle& style, const std::vector& x, const + std::vector& y, const std::vector& z = {}, const + std::vector& w = {}, const std::string& name = ""); - void scatter(const std::vector& x, const std::vector& y, - const std::vector& z, char marker, const std::string& name, - const std::array& color, double opacity); - void scatter(const std::vector& x, const std::vector& y, - char marker, const std::string& name, const std::array& color) - { - scatter(x, y, {}, marker, name, color, 1.); - } - void scatter(const std::vector& x, const std::vector& y, - char marker, const std::array& color) - { - scatter(x, y, marker, "", color); - } - void scatter(const std::vector& x, const std::vector& y, - char marker, const std::string& name) - { - scatter(x, y, marker, name, AutoColor); - } - void scatter(const std::vector& x, const std::vector& y, - char marker) - { - scatter(x, y, marker, "", AutoColor); - } - void scatter(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color) - { - scatter(x, y, 'o', name, color); - } - void scatter(const std::vector& x, const std::vector& y, - const std::array& color) - { - scatter(x, y, 'o', "", color); - } - void scatter(const std::vector& x, const std::vector& y, - const std::string& name) - { - scatter(x, y, 'o', name, AutoColor); - } - void scatter(const std::vector& x, const std::vector& y) - { - scatter(x, y, 'o', "", AutoColor); - } - - void point(double x, double y, char marker, const std::string& name, const - std::array& color) - { - scatter({x}, {y}, marker, name, color); - } - // ... - void point(double x, double y, char marker, const std::array& color) - { - point(x, y, marker, std::string{}, color); - } - void point(double x, double y, char marker, const std::string& name) - { - point(x, y, marker, name, AutoColor); - } - // ... - void point(double x, double y, const std::array& color) - { - point(x, y, '.', std::string{}, color); - } - // ... - void point(double x, double y, char marker) - { - point(x, y, marker, std::string{}, AutoColor); - } - // ... - void point(double x, double y) - { - point(x, y, '.', std::string{}, AutoColor); - } - template - void point(const T& v, char marker, const std::string& name, const std:: - array& color) - { - point(v[0], v[1], marker, name, color); - } - // ... - template - void point(const T& v, char marker, const std::array& color) - { - point(v[0], v[1], marker, std::string{}, color); - } - // ... - template - void point(const T& v, char marker) - { - point(v[0], v[1], marker, std::string{}, AutoColor); - } - // ... - template - void point(const T& v) - { - point(v[0], v[1], '.', std::string{}, AutoColor); - } - - void polar_line(const std::vector& x, const std::vector& - y, const std::string& name, const std::array& color); - // ... - void polar_line(const std::vector& x, const std::vector& - y, const std::string& name) - { - polar_line(x, y, name, AutoColor); - } - void polar_line(const std::vector& x, const std::vector& - y, const std::array& color) - { - polar_line(x, y, std::string{}, color); - } - void polar_line(const std::vector& x, const std::vector& - y) - { - polar_line(x, y, std::string{}, AutoColor); - } - - void polar_scatter(const std::vector& x, const std::vector& - y, char marker, const std::string& name, const std::array& - color); - // ... - void polar_scatter(const std::vector& x, const std::vector& - y, char marker, const std::string& name) - { - polar_scatter(x, y, marker, name, AutoColor); - } - void polar_scatter(const std::vector& x, const std::vector& - y, char marker, const std::array& color) - { - polar_scatter(x, y, marker, std::string{}, color); - } - void polar_scatter(const std::vector& x, const std::vector& - y, const std::string& name, const std::array& color) - { - polar_scatter(x, y, 'o', name, color); - } - void polar_scatter(const std::vector& x, const std::vector& - y, const std::array& color) - { - polar_scatter(x, y, 'o', std::string{}, color); - } - void polar_scatter(const std::vector& x, const std::vector& - y, const std::string& name) - { - polar_scatter(x, y, 'o', name, AutoColor); - } - void polar_scatter(const std::vector& x, const std::vector& - y, char marker) - { - polar_scatter(x, y, marker, std::string{}, AutoColor); - } - void polar_scatter(const std::vector& x, const std::vector& - y) - { - polar_scatter(x, y, 'o', std::string{}, AutoColor); - } - - void stairs(const std::vector& x, const std::vector& y, - const std::string& name, const std::array& color); - void stairs(const std::vector& x, const std::vector& y, - const std::array& color) - { - stairs(x, y, "", color); - } - void stairs(const std::vector& x, const std::vector& y, - const std::string& name) - { - stairs(x, y, name, AutoColor); - } - void stairs(const std::vector& x, const std::vector& y) - { - stairs(x, y, "", AutoColor); - } - - void dashed_stairs(const std::vector& x, const std::vector& - y, const std::string& name, const std::array& color); - void dashed_stairs(const std::vector& x, const std::vector& - y, const std::array& color) - { - dashed_stairs(x, y, "", color); - } - void dashed_stairs(const std::vector& x, const std::vector& - y, const std::string& name) - { - dashed_stairs(x, y, name, AutoColor); - } - void dashed_stairs(const std::vector& x, const std::vector& - y) - { - dashed_stairs(x, y, "", AutoColor); - } - - // ... - void surf(const std::vector& x, const std::vector& y, const - std::vector& z, const std::string& name = ""); - // ... - - // ... + void surf(const std::vector& x, const std::vector& y, + const std::vector& z, const std::string& name = ""); void contour(const std::vector& x, const std::vector& y, const std::vector& z, unsigned int contours = 5, const std:: string& name = ""); - // ... - - // ... void matrix(const std::vector& x, const std::vector& y, const std::vector& z, const std::string& name = ""); - // ... - - //TEMP - void circles(const std::vector& x, const std::vector& y, - const std::vector& r); - //TEMP void legend(unsigned int location = Northeast); void squeeze(); void squeeze_x(); void squeeze_y(); - void x_min(double x); - void x_max(double x); - void y_min(double y); - void y_max(double y); - void z_min(double z); - void z_max(double z); + void setXMin(double x); + void setXMax(double x); + void setYMin(double y); + void setYMax(double y); + void setZMin(double z); + void setZMax(double z); + void setWMin(double w); + void setWMax(double w); void axis_equal(); void axis_equal_image(); void resize(double width, double height); void resize(double size); - void x_precision(int n); - void y_precision(int n); - void z_precision(int n); - void x_format(unsigned int mode); - void y_format(unsigned int mode); - void z_format(unsigned int mode); + void setXPrecision(int n); + void setYPrecision(int n); + void setZPrecision(int n); + void setWPrecision(int n); + void setXFormat(unsigned int mode); + void setYFormat(unsigned int mode); + void setZFormat(unsigned int mode); + void setWFormat(unsigned int mode); void x_log(); void y_log(); void z_log(); - void colorbar(); + void showColorbar(); void scale_x_spacing(double n); void scale_y_spacing(double n); void scale_z_spacing(double n); void x_offset(double n); - void view(double a, double b); + void setView(double az, double el); void opacity(double n); void noSep(); void xTicks(const std::vector& locations, const std::vector< @@ -475,14 +252,14 @@ namespace pgfplotter // Note: ".png" is automatically appended to plot path. template - void plot(const std::string& path, const Plotter& p, Ts&&... q) + void plot(const std::string& path, const Axis& p, Ts&&... q) { - std::vector ptrs = {&p}; + std::vector ptrs = {&p}; plot(path, ptrs, q...); } template - void plot(const std::string& path, std::vector ptrs, const - Plotter& p, Ts&&... q) + void plot(const std::string& path, std::vector ptrs, const + Axis& p, Ts&&... q) { ptrs.push_back(&p); plot(path, ptrs, q...); @@ -490,7 +267,7 @@ namespace pgfplotter template* = nullptr> void plot(const std::string& path, const T& p) { - std::vector ptrs; + std::vector ptrs; ptrs.reserve(p.size()); for(auto& n : p) { @@ -498,7 +275,7 @@ namespace pgfplotter } plot(path, ptrs); } - void plot(const std::string& path, const std::vector& ptrs); + void plot(const std::string& path, const std::vector& ptrs); } #endif diff --git a/test/test.cpp b/test/test.cpp index 5e5d577..e5ab609 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -40,19 +40,19 @@ int main(int, char** argv) } CATCH - pgf::Plotter p; + pgf::Axis p; try { - const auto data = pgfplotter::mesh_grid([](double x, double y){ return - std::sin(x)*std::sin(y); }, 0., 1., 0., 1., 50); + const auto data = pgf::mesh_grid([](double x, double y){ return std:: + sin(x)*std::sin(y); }, 0., 1., 0., 1., 50); p.surf(data[0], data[1], data[2]); - p.x_min(0.); - p.x_max(1.); - p.y_min(0.); - p.y_max(1.); - p.z_min(0.); - p.z_max(1.); - p.view(45., 45.); + p.setXMin(0.); + p.setXMax(1.); + p.setYMin(0.); + p.setYMax(1.); + p.setZMin(0.); + p.setZMax(1.); + p.setView(45., 45.); p.setXLabel("$x$ (\\si{\\lu})"); p.setYLabel("$y$ (\\si{\\arcsec})"); p.setZLabel("$\\dv{^2x}{y^2}$ (\\si{\\lu^2\\per\\arcsec^2})"); @@ -114,7 +114,7 @@ int main(int, char** argv) try { - std::vector v(2, p); + std::vector v(2, p); pgf::plot(outputDir + "/" + PlotName + "-2", v); } CATCH