From 6739019c83b429041027f025fcd181bf80f21b09 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 12 Jan 2024 14:22:23 +0100 Subject: [PATCH] log scale basis in plots --- lib/Core/Plot.cpp | 10 ++++++---- lib/Core/Plot.hpp | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Core/Plot.cpp b/lib/Core/Plot.cpp index a696be6..8377e90 100644 --- a/lib/Core/Plot.cpp +++ b/lib/Core/Plot.cpp @@ -515,14 +515,16 @@ void Dash::operator()(PlotOptions &option) const } // LogScale constructor //////////////////////////////////////////////////////// -LogScale::LogScale(const Axis axis) +LogScale::LogScale(const Axis axis, const double basis) : axis_(axis) +, basis_(basis) {} // Logscale modifier /////////////////////////////////////////////////////////// void LogScale::operator()(PlotOptions &option) const { - option.scaleMode[static_cast(axis_)] |= Plot::Scale::log; + option.scaleMode[static_cast(axis_)] |= Plot::Scale::log; + option.logScaleBasis[static_cast(axis_)] = basis_; } // PlotRange constructors ////////////////////////////////////////////////////// @@ -915,11 +917,11 @@ ostream & Latan::operator<<(ostream &out, const Plot &plot) out << "unset log" << endl; if (plot.options_.scaleMode[x] & Plot::Scale::log) { - out << "set log x" << endl; + out << "set log x " << plot.options_.logScaleBasis[x] << endl;; } if (plot.options_.scaleMode[y] & Plot::Scale::log) { - out << "set log y" << endl; + out << "set log y " << plot.options_.logScaleBasis[y] << endl; } if (!plot.options_.label[x].empty()) { diff --git a/lib/Core/Plot.hpp b/lib/Core/Plot.hpp index af3a6b4..eed57a6 100644 --- a/lib/Core/Plot.hpp +++ b/lib/Core/Plot.hpp @@ -227,6 +227,7 @@ struct PlotOptions std::string caption; std::string title; unsigned int scaleMode[2]; + double logScaleBasis[2]; Range scale[2]; std::string label[2]; std::string lineColor; @@ -314,13 +315,14 @@ class LogScale: public PlotModifier { public: // constructor - explicit LogScale(const Axis axis); + explicit LogScale(const Axis axis, const double basis = 10); // destructor virtual ~LogScale(void) = default; // modifier virtual void operator()(PlotOptions &option) const; private: const Axis axis_; + const double basis_; }; class PlotRange: public PlotModifier