Skip to content

Multicolor Plot Shaded  #247

Closed
Closed
@Davido71

Description

@Davido71

I have been using your plot library quite a lot lately and I'm hoping you can give me some direction on my latest issue.

I'm trying to use PlotShaded() to render different colors when the lines intersect. For example green when line 1 is above line 2 and red when line 1 is below line 2. Is there a way to do this?

Here is what I have so far:

static ImPlotPoint zeroLine(void* data, int i)
{
    return ImPlotPoint(i, 0);
}

static ImPlotPoint getDataSet(void* data, int i)
{
    dataset_t* ptr = reinterpret_cast<dataset_t*>(data);
    return ImPlotPoint(i, ptr->at(i));
}

ImPlot::SetNextFillStyle(ImVec4(0.0f, 0.8f, 0.0f, 1.0f));
ImPlot::PlotShadedG("##wt1", getDataSet, const_cast<dataset_t*>(&data.wt1), zeroLine, nullptr, static_cast<int>(data.wt1.size()), 0.0);

I filled in the lower area red to show what I'm trying to do:

AreaPlotExample

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions