From e2fb07dbeb7ce8a6539e9f014d93da188239f80d Mon Sep 17 00:00:00 2001 From: Ben Reifler Date: Sat, 15 Jun 2024 22:48:43 -0600 Subject: [PATCH] Brings default line style in line with my recent papers. --- axis.cpp | 52 ++++++++++++++++++++++++++++++++++++++++------------ pgfplotter | 25 ++++++++++++++++++------- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/axis.cpp b/axis.cpp index c646098..4984614 100644 --- a/axis.cpp +++ b/axis.cpp @@ -153,22 +153,30 @@ static const std::string Suffix = "_plot_data"; static std::string convert_marker(char marker) { - if(!marker) + if(marker <= 0) { - return "none"; + throw std::runtime_error("Tried to convert unprintable marker."); } if(marker == '^') { return "triangle"; } - if(marker == '.') - { - return "*, mark options = {scale = 0.5}"; - } if(marker == 's') { return "square"; } + if(marker == 'S') + { + return "square*"; + } + if(marker == 'd') + { + return "square, mark options = {rotate = 45, scale = 0.6}"; + } + if(marker == 'D') + { + return "square*, mark options = {rotate = 45, scale = 0.6}"; + } return std::string() + marker; } @@ -457,8 +465,7 @@ void pgfplotter::Axis::draw(const DrawStyle& style, const std::vector& vector& w, const std::string& name) { data.push_back({x, y, z, w}); - markers.emplace_back(convert_marker(style.markStyle.mark), style.markStyle. - size, style.markStyle.spacing); + markers.push_back(style.markStyle); names.push_back(name); colors.push_back(style.color); lineStyles.push_back(style.lineStyle); @@ -1133,7 +1140,6 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con } const bool hasLines = lineStyles[i] != LineStyle::None; - const bool hasMarks = std::get<0>(markers[i]) != "none"; src += is3D ? "\\addplot3+[" : "\\addplot+["; if(lineStyles[i] == LineStyle::Dashed) @@ -1148,8 +1154,30 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con { src += "only marks, "; } - src += "mark = " + std::get<0>(markers[i]) + ", mark size = " + - ToString(3.*std::get<1>(markers[i])); + if(markers[i].mark > 0) + { + src += "mark = " + convert_marker(markers[i].mark) + ", mark size =" + " " + ToString(3.*markers[i].size); + if(markers[i].spacing) + { + src += ", mark repeat = " + std::to_string(markers[i].spacing); + } + } + else if(markers[i].mark < 0) + { + const std::size_t idx = i%DefaultMarks.size(); + src += "mark = " + convert_marker(DefaultMarks[idx].mark) + ", mark" + " size = " + ToString(3.*DefaultMarks[idx].size*markers[i]. + size); + if(markers[i].spacing) + { + src += ", mark repeat = " + std::to_string(markers[i].spacing); + } + } + else + { + src += "mark = none"; + } if(colors[i][0] >= 0) { src += ", rgb color = {" + std::to_string(colors[i][0]) + ", " + @@ -1162,7 +1190,7 @@ std::string pgfplotter::Axis::plot_src(const std::string& path, int subplot) con { src += ", mesh, point meta = explicit, shader = interp"; } - if(hasMarks) + if(markers[i].mark) { src += ", scatter, scatter src = explicit, scatter/use mapped c" "olor = {draw = mapped color, fill = mapped color}"; diff --git a/pgfplotter b/pgfplotter index aa5aa69..48c541a 100644 --- a/pgfplotter +++ b/pgfplotter @@ -65,9 +65,9 @@ namespace pgfplotter char mark; double size; int spacing; - static constexpr MarkStyle Default() + static constexpr MarkStyle Point() { - return {'.', 1., 1}; + return {'*', 0.5, 1}; } static constexpr MarkStyle None() { @@ -75,10 +75,19 @@ namespace pgfplotter } static constexpr MarkStyle Auto() { - return {-1, 0., 0}; + return {-1, 1., 0}; } }; + static constexpr std::array DefaultMarks = + {{ + {'S', 2./3., 0}, + {'*', 2./3., 0}, + {'D', 2./3., 0}, + {'|', 2./3., 0}, + MarkStyle::None() + }}; + struct DrawStyle { std::array color; @@ -87,10 +96,12 @@ namespace pgfplotter double lineWidth; double opacity; }; - static constexpr DrawStyle DefaultLine = {Color::Auto, MarkStyle::None(), + static constexpr DrawStyle BasicLine = {Color::Auto, MarkStyle::None(), + LineStyle::Solid, 1., 1.}; + static constexpr DrawStyle BasicScatter = {Color::Auto, MarkStyle::Point(), + LineStyle::None, 1., 1.}; + static constexpr DrawStyle Default = {Color::Auto, MarkStyle::Auto(), LineStyle::Solid, 1., 1.}; - static constexpr DrawStyle DefaultScatter = {Color::Auto, MarkStyle:: - Default(), LineStyle::None, 1., 1.}; class Axis { @@ -108,7 +119,7 @@ namespace pgfplotter std::vector matrixSurf; std::vector numContours; std::vector names; - std::vector> markers; + std::vector markers; std::vector> colors; std::vector lineStyles; std::vector lineWidths;