admin管理员组

文章数量:1402962

I'm working with Sciplot in C++ and want to do things like display extrema, which I hadn't found a way to do before. But Gnuplot is able to do such things. Can I run Gnuplot commands directly from Sciplot? Or is there another way to plot extrema directly with Sciplot?

What is the best way to proceed?

Thanks :D

I've been messing around with sciplot and reading through some stack overflow problems and other sources. I found some ways to do this with gnuplot, but I don't know how to run these commands with sciplot. I have read the sciplot documentation (which is very poor)

EDIT:
My alternative would be to create a second graph containing only 2 points: the minima and maxima of the graph I want to display, and then somehow display only those points and display the two graphs in one window.

This is what this would look like in code:

static std::pair<point_t, point_t> make_graph(const graph_t& graph, Plot2D& plot, mdf::timestamp_t ref_ts)
{
    point_t max = {0, std::numeric_limits<double>::min()};
    point_t min = {0, std::numeric_limits<double>::max()};
    const size_t size = graph.points.size();
    Vec x(size);
    Vec y(size);
    for(size_t i = 0; i < size; i++)
    {
        x[i] = double(graph.points[i].x - ref_ts)/1'000'000'000.0;
        y[i] = graph.points[i].y;

        max = graph.points[i].y > max.y ? graph.points[i] : max;

        min = graph.points[i].y < min.y ? graph.points[i] : min;
    }

    plot.drawCurve(x, y).label(graph.name).lineWidth(0);
    return {max, min};
}

static void make_extrema(point_t max, point_t min, Plot2D& plot, mdf::timestamp_t ref_ts)
{
    Vec x(2);
    Vec y(2);
    x[0] = double(max.x - ref_ts)/1'000'000'000.0;
    x[1] = double(min.x - ref_ts)/1'000'000'000.0;
    y[0] = (double)max.y;
    y[1] = (double)min.y;
    plot.drawPoints(x, y).labelNone().pointType(6).pointSize(1).lineWidth(0);
}


...
    for(auto graph : graphs)
    {
        auto extrema = make_graph(graph, plot, ref_ts);
    make_extrema(extrema.first, extrema.second, plot, ref_ts);
    }
    Figure fig = {{plot}};
    return fig;

this code produces small circles around the min and max of the graph.

the resulting graph

本文标签: cHow can I execute Gnuplot commands via SciplotStack Overflow