diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..64a6b1f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.0) +project(madplotlib) + +include_directories(${CMAKE_CURRENT_LIST_DIR}) + +find_package(Qt5 REQUIRED COMPONENTS Charts) +include_directories(${Qt5_Charts_INCLUDE_DIRS}) + +find_package(Eigen3 REQUIRED) +include_directories(${Eigen3_INCLUDE_DIRS}) + +add_executable(eigen_test eigen_tests.cpp) +target_link_libraries(eigen_test Qt5::Charts) \ No newline at end of file diff --git a/Madplotlib.h b/Madplotlib.h index 1e38120..708f486 100644 --- a/Madplotlib.h +++ b/Madplotlib.h @@ -24,6 +24,216 @@ #include #include +#pragma once + +#ifndef PLT_ARG_NAMESPACE +#define PLT_ARG_NAMESPACE +#endif + +#ifdef _MSC_VER +#if _MSC_VER >= 1900 +#define PLT_CONSTEXPR constexpr +#else +#define PLT_CONSTEXPR +#endif +#else +#define PLT_CONSTEXPR constexpr +#endif + +#define MO_KEYWORD_INPUT(name, type) \ +namespace tag{ \ + struct name { \ + typedef type Type; \ + typedef const Type& ConstRef; \ + typedef Type& Ref; \ + typedef ConstRef StorageType; \ + typedef const void* VoidType; \ + template \ + static PLT_CONSTEXPR bool AllowedType() { return std::is_same::value; } \ + static VoidType GetPtr(const Type& arg) { \ + return &arg; \ + } \ + template \ + static VoidType GetPtr(const T& arg) { \ + (void)arg; \ + return nullptr; \ + } \ + }; \ +} \ +namespace PLT_ARG_NAMESPACE { \ + static kwargs::TKeyword& name = kwargs::TKeyword::instance; \ +} + + +#define MO_KEYWORD_OUTPUT(name, type) \ +namespace tag{ \ + struct name { \ + typedef type Type; \ + typedef const Type& ConstRef; \ + typedef Type& Ref; \ + typedef Ref StorageType; \ + typedef void* VoidType; \ + template \ + static PLT_CONSTEXPR bool AllowedType() { return std::is_same::value; } \ + static VoidType GetPtr(Type& arg) { \ + return &arg; \ + } \ + template \ + static VoidType GetPtr(const T& arg) { \ + (void)arg; \ + return nullptr; \ + } \ + }; \ +} \ +namespace PLT_ARG_NAMESPACE { \ +static kwargs::TKeyword& name = kwargs::TKeyword::instance; \ +} + +namespace kwargs { + struct TaggedBase {}; + template + struct TaggedArgument : public TaggedBase { + typedef Tag TagType; + explicit TaggedArgument(typename Tag::StorageType val) + : arg(&val) { + } + + typename Tag::VoidType get() const { + return arg; + } + + protected: + typename Tag::VoidType arg; + }; + + template + struct TKeyword { + static TKeyword instance; + TaggedArgument operator=(typename Tag::StorageType data) { + return TaggedArgument(data); + } + }; + template + TKeyword TKeyword::instance; +} + +template +struct ArgType; + +template +struct ArgType<0, T0, T...> { + typedef T0 type; +}; +template +struct ArgType { + typedef typename ArgType::type type; +}; + +template +typename Tag::VoidType GetKeyImpl() { + return 0; +} + +template +PLT_CONSTEXPR int CountTypeImpl(const U& value) { + return std::is_same::value ? 1 : 0; +} + +template +PLT_CONSTEXPR int CountTypeImpl(const U& value, const Args&... args) { + return CountTypeImpl(args...) + (std::is_same::value ? 1 : 0); +} + +template +PLT_CONSTEXPR int CountType(const Args&... args) { + return CountTypeImpl(args...); +} + +template +auto GetPositionalInput(Args&&... as) -> decltype(std::get(std::forward_as_tuple(std::forward(as)...))) { + return std::get(std::forward_as_tuple(std::forward(as)...)); +} + +template +typename std::enable_if::value, typename Tag::VoidType>::type + GetKeyImpl(const T& arg, const Args&... args) { + return std::is_same::value ? const_cast(arg.get()) : const_cast(GetKeyImpl(args...)); +} + +template +typename std::enable_if::value, typename Tag::VoidType>::type + GetKeyImpl(const T& arg, const Args&... args) { +#ifdef __GNUC__ + //static_assert(CountType(arg, args...) <= 1, "Cannot infer type when there are multiple variadic Params with desired type"); +#endif + return Tag::template AllowedType() && Infer ? // This infers the type + Tag::GetPtr(arg) + : const_cast(GetKeyImpl(args...)); +} + +template +typename Tag::ConstRef GetKeywordInput(const Args&... args) { + const void* ptr = GetKeyImpl(args...); + assert(ptr); + return *(static_cast(ptr)); +} + +template +typename Tag::ConstRef GetKeywordInputDefault(typename Tag::ConstRef def, const Args&... args) { + const void* ptr = GetKeyImpl(args...); + if (ptr) + return *static_cast(ptr); + return def; +} + +template +const typename Tag::Type* GetKeywordInputOptional(const Args&... args) { + const void* ptr = GetKeyImpl(args...); + if (ptr) + return static_cast(ptr); + return nullptr; +} + +template +typename Tag::Ref GetKeywordOutput(const Args&... args) { + static_assert(!std::is_const::value, "Tag type is not an output tag"); + void* ptr = GetKeyImpl(args...); + assert(ptr); + return *(static_cast(ptr)); +} + +template +typename Tag::Type* GetKeywordOutputOptional(const Args&... args) { + static_assert(!std::is_const::value, "Tag type is not an output tag"); + void* ptr = GetKeyImpl(args...); + if (ptr) + return (static_cast(ptr)); + return nullptr; +} + +MO_KEYWORD_INPUT(x, Eigen::ArrayXf) +MO_KEYWORD_INPUT(y, Eigen::ArrayXf) +MO_KEYWORD_INPUT(marker, QString) +MO_KEYWORD_INPUT(label, QString) +MO_KEYWORD_INPUT(color, QColor) +MO_KEYWORD_INPUT(linewidth, quint32) +MO_KEYWORD_INPUT(alpha, qreal) +MO_KEYWORD_INPUT(edgecolor, QColor) +MO_KEYWORD_INPUT(markersize, qreal) + +// The below works on MSVC 2015 +/*template +struct is_matrix_expression : std::false_type {}; +template +struct is_matrix_expression() = std::declval(), void())> : std::true_type {};*/ + +// Not sure if there are limitations to this but it seems to work on 2013 +template +struct is_matrix_expression + : std::is_base_of >, std::decay_t > +{}; + + /* Debug control */ @@ -59,7 +269,9 @@ class Madplotlib #if (DEBUG > 0) && (DEBUG < 2) qDebug() << "Madplotlib(): isWidget=" << isWidget; #endif + _xAxisTop = _xAxisBottom = _yAxisLeft = _yAxisRight = nullptr; _chart = new QtCharts::QChart(); + _chartView = new QtCharts::QChartView(_chart); _enableGrid = false; @@ -67,1232 +279,260 @@ class Madplotlib _xMin = _xMax = _yMin = _yMax = 0; _showXticks = _showYticks = SHOW_TICK; - _xTickCount = 7; - _yTickCount = 5; - - _colorIdx = 0; - _colors.push_back(QColor(0x1f77b4)); - _colors.push_back(QColor(0xff7f0e)); - _colors.push_back(QColor(0x2ca02c)); - _colors.push_back(QColor(0xd62728)); - _colors.push_back(QColor(0x9467bd)); - _colors.push_back(QColor(0x8c564b)); - _colors.push_back(QColor(0xe377c2)); - _colors.push_back(QColor(0x7f7f7f)); - _colors.push_back(QColor(0xbcbd22)); - _colors.push_back(QColor(0x17becf)); - } - - void axis(QString cmd) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "axis(): cmd=" << cmd; -#endif - if (cmd == "off") - { - _showYticks = _showXticks = HIDE_TICK; - } - else if (cmd == "xoff") - { - _showXticks = HIDE_TICK; - } - else if (cmd == "yoff") - { - _showYticks = HIDE_TICK; - } - else - { - qCritical() << "axis()!!! options are 'off', 'xoff' and 'yoff'."; - return; - } - } - - /* axis(): gets the current axes limits [xMin, xMax, yMin, yMax]. - */ - void axis(qreal* xMin, qreal* xMax, qreal* yMin, qreal* yMax) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "axis(): _xMin=" << _xMin << " _xMax=" << _xMax << " _yMin=" << _yMin << " _yMax=" << _yMax; -#endif - *xMin = _xMin; - *xMax = _xMax; - *yMin = _yMin; - *yMax = _yMax; - } - - /* axis(): sets the viewport of the axis by a list of [xMin, xMax, yMin, yMax]. - */ - void axis(const qreal& xMin, qreal xMax, const qreal& yMin, const qreal& yMax) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "axis(): xMin=" << xMin << " xMax=" << xMax << " yMin=" << yMin << " yMax=" << yMax; -#endif - _xMin = xMin; - _xMax = xMax; - _yMin = yMin; - _yMax = yMax; - _customLimits = true; - } - - /* xlim(): sets the x limits of the current axes. - */ - void xlim(const qreal& xMin, const qreal& xMax) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "xlim(): xMin=" << xMin << " xMax=" << xMax; -#endif - _xMin = xMin; - _xMax = xMax; - _customLimits = true; - } - - /* ylim(): sets the x limits of the current axes. - */ - void ylim(const qreal& yMin, const qreal& yMax) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "ylim(): yMin=" << yMin << " yMax=" << yMax; -#endif - _yMin = yMin; - _yMax = yMax; - _customLimits = true; - } - - /* title(): defines the title of the chart. - */ - void title(QString string) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "title(): string=" << string; -#endif - _title = string; - } - - /* xlabel(): defines the label displayed below the x axis. - */ - void xlabel(QString label) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "xlabel(): label=" << label; -#endif - _xLabel = label; - } - - /* ylabel(): defines the label displayed to the left of the y axis. - */ - void ylabel(QString label) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "ylabel(): label=" << label; -#endif - _yLabel = label; - } - - /* legend(): defines the position of the legend label inside the chart. - */ - void legend() - { - _legendPos = "lower center"; - } - - /* legend(): defines the position of the legend label inside the chart. - */ - void legend(QString cmd) - { - _legendPos = _parseLegendPos(cmd); - } - - /* grid(): enables or disables the background grid of the chart. - */ - void grid(bool status) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "grid(): status=" << status; -#endif - _enableGrid = status; - } - - /* savefig(): saves the chart displayed by show() as an image on the disk. - */ - void savefig(QString filename) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "savefig(): filename=" << filename; -#endif - if (!_pixmap.isNull()) - _pixmap.save(filename); - } - - /* xticks(): sets the x-limits of the current tick locations and labels. - */ - void xticks(const Eigen::ArrayXf& values, const QVector& labels) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "xticks(): values.sz=" << values.rows() << " labels.sz=" << labels.size(); -#endif - if (values.rows() == 0 && labels.size() == 0) - { - _showXticks = HIDE_TICK; - return; - } - - if (values.rows() != labels.size()) - { - qCritical() << "xticks(): the amount of values and labels must match!"; - return; - } - - for (int i = 0; i < values.rows(); i++) - _xTicks.push_back(QPair(labels[i], values[i])); - - _showXticks = SHOW_CUSTOM_TICK; - -#if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "xticks(): xticks.sz=" << _xTicks.size(); - for (int i = 0; i < _xTicks.size(); i++) - qDebug() << "\t" << _xTicks[i].second << " = " << _xTicks[i].first; -#endif - } - - /* yticks(): sets the y-limits of the current tick locations and labels. - */ - void yticks(const Eigen::ArrayXf& values, const QVector& labels) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "yticks(): values.sz=" << values.rows() << " labels.sz=" << labels.size(); -#endif - if (values.rows() == 0 && labels.size() == 0) - { - _showYticks = HIDE_TICK; - return; - } - - if (values.rows() != labels.size()) - { - qCritical() << "PlotLib::xticks(): the amount of values and labels must match!" ; - return; - } - - for (int i = 0; i < values.rows(); i++) - _yTicks.push_back(QPair(labels[i], values[i])); - - _showYticks = SHOW_CUSTOM_TICK; - -#if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "yticks(): yticks.sz=" << _yTicks.size(); - for (int i = 0; i < _yTicks.size(); i++) - qDebug() << "\t" << _yTicks[i].second << " = " << _yTicks[i].first; -#endif - } - - /* locator_params(): reduce or increase the amount of ticks for each axis. - */ - void locator_params(QString axis, int nbins) - { -#if (DEBUG > 0) && (DEBUG < 2) - qDebug() << "locator_params(): axis=" << axis << " nbins=" << nbins; -#endif - if (axis == "x") - { - _xTickCount = nbins; - } - else if (axis == "y") - { - _yTickCount = nbins; - } - else if (axis == "both") - { - _yTickCount = _xTickCount = nbins; - } - else - { - qCritical() << "locator_params(): '" << axis << "' is not a valid option."; - return; - } - } - - /* Overloaded plot(y) methods with 1-2 parameters */ - - void plot(const Eigen::ArrayXf& y) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const qreal& alpha) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QColor& color) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const quint32& linewidth) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - /* Overloaded plot(y) methods with 3 parameters */ - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const qreal& alpha, const QColor& color) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const qreal& alpha, const quint32& linewidth) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const qreal& alpha, const qreal& markersize) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QColor& color, const quint32& linewidth) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QColor& color, const qreal& markersize) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - /* Overloaded plot(y) methods with 4 parameters */ - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const qreal& alpha, const QColor& color, const quint32& linewidth) - { - plot(y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - /* Overloaded plot(y) methods with 5 parameters */ - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const QColor& edgecolor, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - /* Overloaded plot(y) methods with 6 parameters */ - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const QColor& edgecolor, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1,const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const QColor& edgecolor, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - } - - /* Overloaded plot(y) methods with 7 parameters */ - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(y, cmd2, cmd1, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const QColor& edgecolor, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, cmd2, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(y, cmd2, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - } - - void plot(const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, edgecolor, markersize); - else - plot(y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, edgecolor, markersize); - } - - /* Overloaded plot(x,y) methods with 2-3 parameters */ - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const qreal& alpha) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QColor& color) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const quint32& linewidth) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - /* Overloaded plot(x,y) methods with 4 parameters */ - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const qreal& alpha, const QColor& color) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const qreal& alpha, const quint32& linewidth) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const qreal& alpha, const qreal& markersize) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QColor& color, const quint32& linewidth) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QColor& color, const qreal& markersize) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - /* Overloaded plot(x,y) methods with 5 parameters */ - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const quint32& linewidth, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const qreal& alpha, const QColor& color, const quint32& linewidth) - { - plot(x, y, DEFAULT_MARKER, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - /* Overloaded plot(x,y) methods with 6 parameters */ - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, alpha, DEFAULT_COLOR, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const quint32& linewidth, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const QColor& edgecolor) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - } - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - } + _xTickCount = 7; + _yTickCount = 5; - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); + _colorIdx = 0; + _colors.push_back(QColor(0x1f77b4)); + _colors.push_back(QColor(0xff7f0e)); + _colors.push_back(QColor(0x2ca02c)); + _colors.push_back(QColor(0xd62728)); + _colors.push_back(QColor(0x9467bd)); + _colors.push_back(QColor(0x8c564b)); + _colors.push_back(QColor(0xe377c2)); + _colors.push_back(QColor(0x7f7f7f)); + _colors.push_back(QColor(0xbcbd22)); + _colors.push_back(QColor(0x17becf)); } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const quint32& linewidth, const QColor& edgecolor) + void axis(QString cmd) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "axis(): cmd=" << cmd; +#endif + if (cmd == "off") + { + _showYticks = _showXticks = HIDE_TICK; + } + else if (cmd == "xoff") + { + _showXticks = HIDE_TICK; + } + else if (cmd == "yoff") + { + _showYticks = HIDE_TICK; + } else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, DEFAULT_COLOR, linewidth, edgecolor, DEFAULT_MARKERSZ); + { + qCritical() << "axis()!!! options are 'off', 'xoff' and 'yoff'."; + return; + } } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const QColor& edgecolor, const qreal& markersize) + /* axis(): gets the current axes limits [xMin, xMax, yMin, yMax]. + */ + void axis(qreal* xMin, qreal* xMax, qreal* yMin, qreal* yMax) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "axis(): _xMin=" << _xMin << " _xMax=" << _xMax << " _yMin=" << _yMin << " _yMax=" << _yMax; +#endif + *xMin = _xMin; + *xMax = _xMax; + *yMin = _yMin; + *yMax = _yMax; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth, const qreal& markersize) + /* axis(): sets the viewport of the axis by a list of [xMin, xMax, yMin, yMax]. + */ + void axis(const qreal& xMin, qreal xMax, const qreal& yMin, const qreal& yMax) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "axis(): xMin=" << xMin << " xMax=" << xMax << " yMin=" << yMin << " yMax=" << yMax; +#endif + _xMin = xMin; + _xMax = xMax; + _yMin = yMin; + _yMax = yMax; + _customLimits = true; } - /* Overloaded plot(x,y) methods with 7 parameters */ - - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const QColor& edgecolor) + /* xlim(): sets the x limits of the current axes. + */ + void xlim(const qreal& xMin, const qreal& xMax) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, DEFAULT_MARKERSZ); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "xlim(): xMin=" << xMin << " xMax=" << xMax; +#endif + _xMin = xMin; + _xMax = xMax; + _customLimits = true; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth) + /* ylim(): sets the x limits of the current axes. + */ + void ylim(const qreal& yMin, const qreal& yMax) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, DEFAULT_MARKERSZ); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "ylim(): yMin=" << yMin << " yMax=" << yMax; +#endif + _yMin = yMin; + _yMax = yMax; + _customLimits = true; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const qreal& markersize) + /* title(): defines the title of the chart. + */ + void title(QString string) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, DEFAULT_EDGECOLOR, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "title(): string=" << string; +#endif + _title = string; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const quint32& linewidth, const qreal& markersize) + /* xlabel(): defines the label displayed below the x axis. + */ + void xlabel(QString label) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, alpha, DEFAULT_COLOR, linewidth, DEFAULT_EDGECOLOR, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "xlabel(): label=" << label; +#endif + _xLabel = label; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const QColor& edgecolor) + /* ylabel(): defines the label displayed to the left of the y axis. + */ + void ylabel(QString label) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, DEFAULT_MARKERSZ); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "ylabel(): label=" << label; +#endif + _yLabel = label; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const QColor& edgecolor, const qreal& markersize) + /* legend(): defines the position of the legend label inside the chart. + */ + void legend() { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, DEFAULT_LINEW, edgecolor, markersize); + _legendPos = "lower center"; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const qreal& markersize) + /* legend(): defines the position of the legend label inside the chart. + */ + void legend(QString cmd) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, DEFAULT_ALPHA, color, linewidth, DEFAULT_EDGECOLOR, markersize); + _legendPos = _parseLegendPos(cmd); } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1,const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor) + /* grid(): enables or disables the background grid of the chart. + */ + void grid(bool status) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "grid(): status=" << status; +#endif + _enableGrid = status; } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const QColor& edgecolor, const qreal& markersize) + /* savefig(): saves the chart displayed by show() as an image on the disk. + */ + void savefig(QString filename) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "savefig(): filename=" << filename; +#endif + if (!_pixmap.isNull()) + _pixmap.save(filename); + else if(_isWidget && _chartView){ + _pixmap = _chartView->grab(); + } } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth, const qreal& markersize) + /* xticks(): sets the x-limits of the current tick locations and labels. + */ + void xticks(const Eigen::ArrayXf& values, const QVector& labels) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "xticks(): values.sz=" << values.rows() << " labels.sz=" << labels.size(); +#endif + if (values.rows() == 0 && labels.size() == 0) + { + _showXticks = HIDE_TICK; + return; + } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) - { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - } + if (values.rows() != labels.size()) + { + qCritical() << "xticks(): the amount of values and labels must match!"; + return; + } - /* Overloaded plot(x,y) methods with 8 parameters */ + for (int i = 0; i < values.rows(); i++) + _xTicks.push_back(QPair(labels[i], values[i])); - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor) - { - _check_cmds_are_good(cmd1, cmd2); + _showXticks = SHOW_CUSTOM_TICK; - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); - else - plot(x, y, cmd2, cmd1, alpha, color, linewidth, edgecolor, DEFAULT_MARKERSZ); +#if (DEBUG > 1) && (DEBUG < 3) + qDebug() << "xticks(): xticks.sz=" << _xTicks.size(); + for (int i = 0; i < _xTicks.size(); i++) + qDebug() << "\t" << _xTicks[i].second << " = " << _xTicks[i].first; +#endif } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const QColor& edgecolor, const qreal& markersize) + /* yticks(): sets the y-limits of the current tick locations and labels. + */ + void yticks(const Eigen::ArrayXf& values, const QVector& labels) { - _check_cmds_are_good(cmd1, cmd2); - - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - else - plot(x, y, cmd2, cmd1, alpha, color, DEFAULT_LINEW, edgecolor, markersize); - } +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "yticks(): values.sz=" << values.rows() << " labels.sz=" << labels.size(); +#endif + if (values.rows() == 0 && labels.size() == 0) + { + _showYticks = HIDE_TICK; + return; + } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const qreal& alpha, const QColor& color, const quint32& linewidth, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); + if (values.rows() != labels.size()) + { + qCritical() << "PlotLib::xticks(): the amount of values and labels must match!" ; + return; + } - if (_is_marker(cmd1)) - plot(x, y, cmd1, cmd2, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - else - plot(x, y, cmd2, cmd1, alpha, color, linewidth, DEFAULT_EDGECOLOR, markersize); - } + for (int i = 0; i < values.rows(); i++) + _yTicks.push_back(QPair(labels[i], values[i])); - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const QString& cmd2, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) - { - _check_cmds_are_good(cmd1, cmd2); + _showYticks = SHOW_CUSTOM_TICK; - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); - else - plot(x, y, DEFAULT_MARKER, cmd1, DEFAULT_ALPHA, color, linewidth, edgecolor, markersize); +#if (DEBUG > 1) && (DEBUG < 3) + qDebug() << "yticks(): yticks.sz=" << _yTicks.size(); + for (int i = 0; i < _yTicks.size(); i++) + qDebug() << "\t" << _yTicks[i].second << " = " << _yTicks[i].first; +#endif } - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const QString& cmd1, const qreal& alpha, const QColor& color, const quint32& linewidth, const QColor& edgecolor, const qreal& markersize) + /* locator_params(): reduce or increase the amount of ticks for each axis. + */ + void locator_params(QString axis, int nbins) { - if (_is_marker(cmd1)) - plot(x, y, cmd1, DEFAULT_LEGEND, alpha, color, linewidth, edgecolor, markersize); +#if (DEBUG > 0) && (DEBUG < 2) + qDebug() << "locator_params(): axis=" << axis << " nbins=" << nbins; +#endif + if (axis == "x") + { + _xTickCount = nbins; + } + else if (axis == "y") + { + _yTickCount = nbins; + } + else if (axis == "both") + { + _yTickCount = _xTickCount = nbins; + } else - plot(x, y, DEFAULT_MARKER, cmd1, alpha, color, linewidth, edgecolor, markersize); + { + qCritical() << "locator_params(): '" << axis << "' is not a valid option."; + return; + } } - - /* plot(y): this implementation handles calls that do not specify X data. - * For that purpose, this method fabricates the data needed to plot Y series - * correctly on the chart. - */ - void plot(const Eigen::ArrayXf& y, const QString& marker, const QString& label, - const qreal& alpha, const QColor& color, const quint32& linewidth, - const QColor& edgecolor, const qreal& markersize) + + template + typename std::enable_if::value>::type plot(const Eigen::ArrayXf& y, const T& arg1, const Args&... args) { #if (DEBUG > 0) && (DEBUG < 2) qDebug() << "plot(y): marker=" << marker << " alpha=" << alpha << - " color=" << color << " edgecolor=" << edgecolor << - " linewidth=" << linewidth << " markersize=" << markersize; + " color=" << color << " edgecolor=" << edgecolor << + " linewidth=" << linewidth << " markersize=" << markersize; #endif if (y.rows() == 0) { @@ -1320,13 +560,13 @@ class Madplotlib x_value += x_inc; #if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "plot(y): generated x[" << i << "]=" << x[i]; + qDebug() << "plot(y): generated x[" << i << "]=" << x[i]; #endif } - - plot(x, y, marker, label, alpha, color, linewidth, edgecolor, markersize); + plotXY(x, y, arg1, args...); } + /* plot(): called when user needs to put data on a chart. * x: an array that stores x axis values. * y: an array that stores y axis values. @@ -1337,11 +577,24 @@ class Madplotlib * linewidth: defines the width of the pen used to draw "-" marker. * markersize: defines the size of "o" marker. */ - void plot(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, - const QString& marker, const QString& label, - const qreal& alpha, const QColor& color, const quint32& linewidth, - const QColor& edgecolor, const qreal& markersize) - { + template + typename std::enable_if::value>::type plot(const Eigen::ArrayXf& x, const T& y, const Args&... args) + { + plotXY(x, y, args...); + } + + template + void plotXY(const Eigen::ArrayXf& x, const Eigen::ArrayXf& y, const Args&... args) + { + const QString marker = GetKeywordInputDefault(DEFAULT_MARKER, args...); + const QString label = GetKeywordInputDefault(DEFAULT_LEGEND, args...); + const qreal& alpha = GetKeywordInputDefault(DEFAULT_ALPHA, args...); + const QColor color = GetKeywordInputDefault(DEFAULT_COLOR, args...); + const quint32& linewidth = GetKeywordInputDefault(DEFAULT_LINEW, args...); + const QColor edgecolor = GetKeywordInputDefault(DEFAULT_EDGECOLOR, args...); + const qreal& markersize = GetKeywordInputDefault(DEFAULT_MARKERSZ, args...); + + #if (DEBUG > 0) && (DEBUG < 2) qDebug() << "plot(x,y): marker:" << marker << " alpha:" << alpha << " color:" << color << " edgecolor:" << edgecolor << @@ -1391,31 +644,37 @@ class Madplotlib "] yrange [" << _yMin << "," << _yMax << "]"; #endif - QtCharts::QXYSeries* series = NULL; - if (marker == "o" || marker == "s") // it's a scatter plot! - { -#if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "plot(x,y): scatter plot"; -#endif - QtCharts::QScatterSeries* s = new QtCharts::QScatterSeries(); - s->setMarkerSize(markersize); // symbol size - - if (marker == "o") - s->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeCircle); - - if (marker == "s") - s->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeRectangle); - - series = (QtCharts::QXYSeries*)s; - } - else // draw line - { -#if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "plot(x,y): line plot"; -#endif - series = new QtCharts::QLineSeries(); + std::shared_ptr series; + auto itr = _seriesVec.find(_legend); + if(itr != _seriesVec.end()){ + series = *itr; + }else{ + if (marker == "o" || marker == "s") // it's a scatter plot! + { + #if (DEBUG > 1) && (DEBUG < 3) + qDebug() << "plot(x,y): scatter plot"; + #endif + QtCharts::QScatterSeries* s = new QtCharts::QScatterSeries(); + s->setMarkerSize(markersize); // symbol size + + if (marker == "o") + s->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeCircle); + + if (marker == "s") + s->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeRectangle); + + series.reset((QtCharts::QXYSeries*)s); + series->setUseOpenGL(true); + } + else // draw line + { + #if (DEBUG > 1) && (DEBUG < 3) + qDebug() << "plot(x,y): line plot"; + #endif + series.reset(new QtCharts::QLineSeries()); + series->setUseOpenGL(true); + } } - // Call a string parser! Ex: "label=Trump Tweets" becomes "Trump Tweets" _parseLegend(); if (_legend.size()) @@ -1425,13 +684,19 @@ class Madplotlib #endif series->setName(_legend); } - - for (int i = 0; i < x.rows(); i++) - { + + if(series->count() == x.rows()){ + for (int i = 0; i < x.rows(); i++) + series->replace(i, x[i], y[i]); + }else{ + series->clear(); + for (int i = 0; i < x.rows(); i++) + { #if (DEBUG > 1) && (DEBUG < 3) - qDebug() << "plot(x,y): x[" << i << "]=" << x[i] << " y[" << i << "]=" << y[i]; + qDebug() << "plot(x,y): x[" << i << "]=" << x[i] << " y[" << i << "]=" << y[i]; #endif - series->append(x[i], y[i]); + series->append(x[i], y[i]); + } } // Customize series color and transparency @@ -1483,7 +748,8 @@ class Madplotlib if (_colorIdx >= _colors.size()) _colorIdx = 0; - _seriesVec.push_back(series); + //_seriesVec.push_back(series); + _seriesVec[_legend] = series; #if (DEBUG > 0) && (DEBUG < 2) qDebug() << "plot(x,y): -----"; @@ -1542,7 +808,7 @@ class Madplotlib qDebug() << "show(): xrange [" << _xMin << "," << _xMax << "] " << " yrange [" << _yMin << "," << _yMax << "]"; #endif - + QPen axisPen(Qt::black); // default axis line color and width axisPen.setWidth(1); @@ -1550,15 +816,22 @@ class Madplotlib QtCharts::QCategoryAxis* categoryX = NULL; if (_showXticks == SHOW_TICK || _showXticks == HIDE_TICK) { - axisX = new QtCharts::QValueAxis; + bool add = true; + if (_xAxisBottom){ + axisX = dynamic_cast(_xAxisBottom); + add = false; + }else{ + axisX = new QtCharts::QValueAxis; + } axisX->setGridLineVisible(_enableGrid); axisX->setTitleText(_xLabel); axisX->setLinePen(axisPen); axisX->setRange(_xMin, _xMax); axisX->setTickCount(_xTickCount); if (!_customLimits) axisX->applyNiceNumbers(); - _chart->addAxis(axisX, Qt::AlignBottom); - + if(add) + _chart->addAxis(axisX, Qt::AlignBottom); + _xAxisBottom = axisX; if (_showXticks == HIDE_TICK) axisX->setLabelsVisible(false); } @@ -1580,23 +853,34 @@ class Madplotlib categoryX->setRange(_xMin, _xMax); categoryX->setTickCount(_xTicks.size()); + if(_xAxisBottom) + _chart->removeAxis(_xAxisBottom); _chart->addAxis(categoryX, Qt::AlignBottom); + _xAxisBottom = categoryX; } QtCharts::QValueAxis* axisY = NULL; QtCharts::QCategoryAxis* categoryY = NULL; if (_showYticks == SHOW_TICK || _showYticks == HIDE_TICK) // this is the default ticks setup { - axisY = new QtCharts::QValueAxis; + bool add = true; + if(_yAxisLeft){ + axisY = dynamic_cast(_yAxisLeft); + add = false; + }else{ + axisY = new QtCharts::QValueAxis; + } + axisY->setGridLineVisible(_enableGrid); axisY->setTitleText(_yLabel); axisY->setLinePen(axisPen); axisY->setRange(_yMin, _yMax); axisY->setTickCount(_yTickCount); if (!_customLimits) axisY->applyNiceNumbers(); - //axisY->setBase(8.0); // 1, 8, 64, 512, 4096 - _chart->addAxis(axisY, Qt::AlignLeft); - + if(add) + _chart->addAxis(axisY, Qt::AlignLeft); + _yAxisLeft = axisY; + if (_showYticks == HIDE_TICK) axisY->setLabelsVisible(false); } @@ -1618,41 +902,39 @@ class Madplotlib categoryY->setRange(_yMin, _yMax); categoryY->setTickCount(_yTicks.size()); + if(_yAxisLeft) + _chart->removeAxis(_yAxisLeft); _chart->addAxis(categoryY, Qt::AlignLeft); + _yAxisLeft = categoryY; } /* Other possible customizations such as margins and background color */ - - //_chart->setMargins(QMargins(0,0,0,0)); - //_chart->setPlotAreaBackgroundBrush(QBrush(Qt::black)); - //_chart->setPlotAreaBackgroundVisible(true); - // Remove (fat) exterior margins from QChart _chart->layout()->setContentsMargins(0, 0, 0, 0); _chart->setBackgroundRoundness(0); /* Add series of data */ - - for (int i = 0; i < _seriesVec.size(); i++) + _chart->removeAllSeries(); + for(auto itr : _seriesVec) { - _chart->addSeries(_seriesVec[i]); + _chart->addSeries(itr.get()); if (_showXticks == SHOW_TICK || _showXticks == HIDE_TICK) { - _seriesVec[i]->attachAxis(axisX); + itr->attachAxis(axisX); } else if (_showXticks == SHOW_CUSTOM_TICK) { - _seriesVec[i]->attachAxis(categoryX); + itr->attachAxis(categoryX); } if (_showYticks == SHOW_TICK || _showYticks == HIDE_TICK) { - _seriesVec[i]->attachAxis(axisY); + itr->attachAxis(axisY); } else if (_showYticks == SHOW_CUSTOM_TICK) { - _seriesVec[i]->attachAxis(categoryY); + itr->attachAxis(categoryY); } } @@ -1661,7 +943,7 @@ class Madplotlib // Take a screenshot of the widget before it's destroyed // so it can be saved later, when savefig() is invoked after show(). - _pixmap = _chartView->grab(); + _chartView->show(); @@ -1669,14 +951,14 @@ class Madplotlib // However, is this chart is supposed to be a real widget, then do none of this. if (!_isWidget) { + _pixmap = _chartView->grab(); _chartView->setAttribute(Qt::WA_DeleteOnClose); // This deletes _chartView! QEventLoop loop; QObject::connect(_chartView, SIGNAL(destroyed()), &loop, SLOT(quit())); loop.exec(); // _chartView was automatically deleted. Release all the other resources! - for (int i = 0; i < _seriesVec.size(); i++) - delete _seriesVec[i]; + //_seriesVec.clear(); } #if (DEBUG > 0) && (DEBUG < 2) @@ -1684,6 +966,9 @@ class Madplotlib #endif } + void clear(){ + _seriesVec.clear(); + } private: @@ -1775,7 +1060,8 @@ class Madplotlib QPixmap _pixmap; // show() screenshots the widget, savefig() writes it on the disk QtCharts::QChart* _chart; // manages the graphical representation of the chart's series, legends & axes QtCharts::QChartView* _chartView; // standalone widget that can display charts - QVector _seriesVec; // every plot() creates a new series of data that is stored here + QMap> _seriesVec; // every plot() creates a new series of data that is stored here + bool _isWidget; // true: show() doesn't block so this can be used as widget QString _legend; @@ -1802,4 +1088,8 @@ class Madplotlib qreal _yMax; // Y axis max limit bool _enableGrid; // flag that show/hides the background grid + QtCharts::QAbstractAxis* _yAxisLeft; + QtCharts::QAbstractAxis* _yAxisRight; + QtCharts::QAbstractAxis* _xAxisBottom; + QtCharts::QAbstractAxis* _xAxisTop; }; diff --git a/eigen_tests.cpp b/eigen_tests.cpp index bce5333..9d14ee8 100644 --- a/eigen_tests.cpp +++ b/eigen_tests.cpp @@ -84,9 +84,9 @@ void test3() Madplotlib plt; plt.title("Test 3: Multiple Data Series"); plt.axis(0, 25, 0, 14); - plt.plot(x, y, QString("--"), QString("label=Dashed Line")); - plt.plot(x, y+5, QString("label=Default Line"), (quint32)4); - plt.plot(x, y+10, QString("."), QString("label=Dotted Line")); + plt.plot(x, y, marker=QString("--"), label=QString("label=Dashed Line")); + plt.plot(x, y+5, label=QString("label=Default Line"), (quint32)4); + plt.plot(x, y+10, QString("."), label=QString("label=Dotted Line")); plt.legend(); // default position is "lower center" plt.show(); @@ -125,8 +125,8 @@ void test4() plt.title("Test 4: Random Scatter Plot"); plt.locator_params("x", 10); plt.axis(-25, 100, -25, 100); - plt.plot(x, y, QString("o"), 0.7f, QColor(255, 0, 0), 8.0f); // red, 30% transparent, markersize 8 - plt.plot(x2, y2, QString("o"), 0.5f, QColor(0, 0, 255)); // blue, 50% transparent + plt.plot(x, y, marker=QString("o"), 0.7f, QColor(255, 0, 0), 8.0f); // red, 30% transparent, markersize 8 + plt.plot(x2, y2, marker=QString("o"), 0.5f, QColor(0, 0, 255)); // blue, 50% transparent plt.show(); #ifdef SCRSHOT @@ -191,10 +191,10 @@ void test6() 105, 111, 120, 126, 120, 104, 85, 92; Madplotlib plt; - plt.plot(x, y, QColor(0xFF2700)); // red - plt.plot(x, y, QString("o"), QColor(0xFF2700)); - plt.plot(x, y-40, QColor(0x008FD5)); // blue - plt.plot(x, y-40, QString("o"), QColor(0x008FD5)); + plt.plot(x, y, color=QColor(0xFF2700)); // red + plt.plot(x, y, marker=QString("o"), color=QColor(0xFF2700)); + plt.plot(x, y-40, color=QColor(0x008FD5)); // blue + plt.plot(x, y-40, marker=QString("o"), color=QColor(0x008FD5)); plt.title("Test 6: Line + Scatter"); plt.xlabel("X values"); @@ -240,7 +240,7 @@ void test7() // On Qt 7.5, Qt Charts has a bug spacing correctly categories on negative Y axis (-1, 1). // For now, drawing (y+1) will bypass that since the values will fall between (0, 2). plt.ylim(0, 2); - plt.plot(x, y+1, QString("o"), 1.f, 2, 7.0f); // alpha=1.f, linewidth=2, markersize=7.f + plt.plot(x, y+1, marker=QString("o"), alpha=1.f, linewidth=2, markersize=7.0f); // alpha=1.f, linewidth=2, markersize=7.f plt.grid(true); plt.show(); @@ -265,13 +265,13 @@ void test8() Madplotlib plt; plt.title("Test 8: Line + Square Markers + Hidden Ticks"); plt.axis("off"); - plt.plot(x, x.sqrt(), QColor(0, 0, 0)); - plt.plot(x, -x.sqrt(), QColor(0, 0, 0)); + plt.plot(x, x.sqrt(), color=QColor(0, 0, 0)); + plt.plot(x, -x.sqrt(), color = QColor(0, 0, 0)); Eigen::ArrayXf noise = Eigen::ArrayXf::Random(50) * 2; - plt.plot(x, x.sqrt() - noise, QString("s"), 0.7f, QColor(19, 154, 255), QColor(19, 154, 255)); // red squares without black edges - plt.plot(x, -x.sqrt() - noise, QString("s"), 0.7f, QColor(255, 41, 5), QColor(255, 41, 5)); // blue squares without black edges + plt.plot(x, x.sqrt() - noise, marker=QString("s"), alpha = 0.7f, color=QColor(19, 154, 255), edgecolor=QColor(19, 154, 255)); // red squares without black edges + plt.plot(x, -x.sqrt() - noise, marker = QString("s"), alpha = 0.7f, color=QColor(255, 41, 5), edgecolor=QColor(255, 41, 5)); // blue squares without black edges plt.show(); #ifdef SCRSHOT @@ -345,7 +345,7 @@ void test10() // On Qt 7.5, Qt Charts has a bug spacing correctly categories on negative X axis (-3.1, 3.1). // For now, make sure you are using only positive X values to bypass that problem. plt.plot(X, C); - plt.plot(X, S, QString("--")); + plt.plot(X, S, marker=QString("--")); plt.xlim(0, 2*pi); plt.xticks(x_ticks, x_labels); plt.show();