我怎样才能做到“实时”? 用 wxMathPlot 绘图?

发布于 2024-07-23 09:49:03 字数 350 浏览 4 评论 0 原文

我正在考虑使用 wxMathPlot 来绘制/绘制一些连续到达的数据。 我想用它来绘制“实时”绘图/图表。 那可能吗?

IE 我不想要一次性读取文件的静态图 - 我想要绘制流数据并继续到图的右侧 - (并让左侧脱落/滚动到视图之外)

编辑

我仍然没有得到答案。 wxmathPlot 库中有一个有趣的类,称为 mpFXYVector,但它似乎只是从数据向量中绘制一个图。 我想要的是可以输入流并水平滚动图表的东西(如果需要的话还可以调整比例大小)

I am thinking of using wxMathPlot for plotting/graphing some data that arrives continuously. I want to draw "Real-time" plot/graph using it. Is that possible?

I.E. I don't want just a static graph of a one-time read of a file - I want the streaming data plotted and continued out to the right of the graph - (and let the left side fall off/scroll out of view)

EDIT

I still have not gotten an answer for this. There is an interesting class in the wxmathPlot library called mpFXYVector but that appears just to draw one plot from a vector of data. What I want is something that can be fed a stream and scroll the graph horizontally (and also resize the scale if needed)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

调妓 2024-07-30 09:49:03

谢谢乌鸦点...!! 我按照你说的做了..它工作完美!
这是我的 AddData() 函数:

void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
    {
        // Check if the data vectora are of the same size
        if (xs.size() != ys.size()) {
            wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
            return;
        }

        //Delete first point if you need a filo buffer (i dont need it)
        //xs.erase(xs.begin());
        //xy.erase(xy.begin());

        //Add new Data points at the end
        xs.push_back(x);
        ys.push_back(y);


        // Copy the data:
        m_xs = xs;
        m_ys = ys;

        // Update internal variables for the bounding box.
        if (xs.size()>0)
        {
            m_minX  = xs[0];
            m_maxX  = xs[0];
            m_minY  = ys[0];
            m_maxY  = ys[0];

            std::vector<double>::const_iterator  it;

            for (it=xs.begin();it!=xs.end();it++)
            {
                if (*it<m_minX) m_minX=*it;
                if (*it>m_maxX) m_maxX=*it;
            }
            for (it=ys.begin();it!=ys.end();it++)
            {
                if (*it<m_minY) m_minY=*it;
                if (*it>m_maxY) m_maxY=*it;
            }
            m_minX-=0.5f;
            m_minY-=0.5f;
            m_maxX+=0.5f;
            m_maxY+=0.5f;
        }
        else
        {
            m_minX  = -1;
            m_maxX  = 1;
            m_minY  = -1;
            m_maxY  = 1;
        }
    }

在 Main() 中你只需要:

m_Vector->AddData(xPos,yPos,vectorX, vectorY);
m_plot->Fit();

Thanks ravenspoint...!! I did what you said.. It works flawless!
here is my AddData() function:

void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
    {
        // Check if the data vectora are of the same size
        if (xs.size() != ys.size()) {
            wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
            return;
        }

        //Delete first point if you need a filo buffer (i dont need it)
        //xs.erase(xs.begin());
        //xy.erase(xy.begin());

        //Add new Data points at the end
        xs.push_back(x);
        ys.push_back(y);


        // Copy the data:
        m_xs = xs;
        m_ys = ys;

        // Update internal variables for the bounding box.
        if (xs.size()>0)
        {
            m_minX  = xs[0];
            m_maxX  = xs[0];
            m_minY  = ys[0];
            m_maxY  = ys[0];

            std::vector<double>::const_iterator  it;

            for (it=xs.begin();it!=xs.end();it++)
            {
                if (*it<m_minX) m_minX=*it;
                if (*it>m_maxX) m_maxX=*it;
            }
            for (it=ys.begin();it!=ys.end();it++)
            {
                if (*it<m_minY) m_minY=*it;
                if (*it>m_maxY) m_maxY=*it;
            }
            m_minX-=0.5f;
            m_minY-=0.5f;
            m_maxX+=0.5f;
            m_maxY+=0.5f;
        }
        else
        {
            m_minX  = -1;
            m_maxX  = 1;
            m_minY  = -1;
            m_maxY  = 1;
        }
    }

in the Main() you only have to:

m_Vector->AddData(xPos,yPos,vectorX, vectorY);
m_plot->Fit();
平定天下 2024-07-30 09:49:03

我认为 mpFXYVector 是正确的选择。

处理这个问题的最简单方法可能是为 mpFXYVector 编写一个包装类,它保存最近数据点的 FIFO 缓冲区。 每次新数据点到达时,将其添加到 FIFO 缓冲区,这将删除最旧的点,然后使用更新的缓冲区加载 mpFXYVector。 wxMathPlot 类 mpWindow 将处理您需要的其余部分。

更优雅的方法是 mpFXYVector 的专门化,它使用 mpFXYVector 中的简单向量来实现 FIFO 缓冲区。 这样做的优点是您只持有显示数据的一份副本。 除非您要显示数千个点,否则我怀疑从 mpFXYVector 继承的优势是否值得付出额外的麻烦,而不是简单地使用 mpFXYVector 记录的接口。

查看详细信息后,唯一棘手的一点是用新方法 Add() 替换 mpFXYVector::SetData(),以便在数据点到达时添加它们。 新方法需要将 mpFXYVector 向量作为 FIFO 缓冲区进行管理,并重新实现代码以更新边界框(不幸的是,编写时没有考虑到继承)。

结果是,与使用包装器相比,专业化提供的解决方案具有更小的内存需求和更大的灵活性。

I think mpFXYVector is the way to go.

The simplest way to deal with this might be to write a wrapper class for mpFXYVector which holds a FIFO buffer of recent data points. Each time a new datapoint arrives, add it to the FIFO buffer, which will drop the oldest point, then load mpFXYVector with the updated buffer. The wxMathPlot class mpWindow will look after the rest of what you need.

A more elegant approach would be a specialization of mpFXYVector which implements the FIFO buffer, using the simple vectors in mpFXYVector. The advantage of this would be that you are holding just one copy of the display data. Unless you are displaying many thousands of points, I doubt the advantage is worth the extra trouble of inheriting from mpFXYVector, rather than simply using the mpFXYVector documented interface.

After looking at the details, the only tricky bit is to replace mpFXYVector::SetData() with a new method Add() to add data points as they arrive. The new method needs to manage the mpFXYVector vectors as FIFO buffers, and to re-implement the code to update the bounding box ( which unfortunately was not written with inheritance in mind ).

The result is that specialization gives a solution with a smaller memory requirement and more flexibility than using a wrapper.

躲猫猫 2024-07-30 09:49:03

我知道这是一个旧线程,但我需要使用 wxMathPlot 绘制滚动 X 轴。

我对 jayjo 的代码做了一个简单的修改,以使 X 轴滚动工作。

我希望这有帮助。

void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
{
    // Check if the data vectora are of the same size
    if (xs.size() != ys.size()) {
        wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
        return;
    }

    //After a certain number of points implement a FIFO buffer
    //As plotting too many points can cause missing data
    if (x > 300)
    {
        xs.erase(xs.begin());
        ys.erase(ys.begin());
    }



    //Add new Data points at the end
    xs.push_back(x);
    ys.push_back(y);


    // Copy the data:
    m_xs = xs;
    m_ys = ys;

    // Update internal variables for the bounding box.
    if (xs.size()>0)
    {
        m_minX  = xs[0];
        m_maxX  = xs[0];
        m_minY  = ys[0];
        m_maxY  = ys[0];

        std::vector<double>::const_iterator  it;

        for (it=xs.begin();it!=xs.end();it++)
        {
            if (*it<m_minX) m_minX=*it;
            if (*it>m_maxX) m_maxX=*it;
        }
        for (it=ys.begin();it!=ys.end();it++)
        {
            if (*it<m_minY) m_minY=*it;
            if (*it>m_maxY) m_maxY=*it;
        }
        m_minX-=0.5f;
        m_minY-=0.5f;
        m_maxX+=0.5f;
        m_maxY+=0.5f;
    }
    else
    {
        m_minX  = -1;
        m_maxX  = 1;
        m_minY  = -1;
        m_maxY  = 1;
    }
}

I know this is an old thread but I needed to plot a scrolling X axis with wxMathPlot.

I've done a simple modification to jayjo's code to make X axis scrolling work.

I hoe this helps.

void mpFXYVector::AddData(float x, float y, std::vector<double> &xs, std::vector<double> &ys)
{
    // Check if the data vectora are of the same size
    if (xs.size() != ys.size()) {
        wxLogError(_("wxMathPlot error: X and Y vector are not of the same length!"));
        return;
    }

    //After a certain number of points implement a FIFO buffer
    //As plotting too many points can cause missing data
    if (x > 300)
    {
        xs.erase(xs.begin());
        ys.erase(ys.begin());
    }



    //Add new Data points at the end
    xs.push_back(x);
    ys.push_back(y);


    // Copy the data:
    m_xs = xs;
    m_ys = ys;

    // Update internal variables for the bounding box.
    if (xs.size()>0)
    {
        m_minX  = xs[0];
        m_maxX  = xs[0];
        m_minY  = ys[0];
        m_maxY  = ys[0];

        std::vector<double>::const_iterator  it;

        for (it=xs.begin();it!=xs.end();it++)
        {
            if (*it<m_minX) m_minX=*it;
            if (*it>m_maxX) m_maxX=*it;
        }
        for (it=ys.begin();it!=ys.end();it++)
        {
            if (*it<m_minY) m_minY=*it;
            if (*it>m_maxY) m_maxY=*it;
        }
        m_minX-=0.5f;
        m_minY-=0.5f;
        m_maxX+=0.5f;
        m_maxY+=0.5f;
    }
    else
    {
        m_minX  = -1;
        m_maxX  = 1;
        m_minY  = -1;
        m_maxY  = 1;
    }
}
蓝海似她心 2024-07-30 09:49:03

我对 wxMathPlot 没有任何个人经验,但我多年来一直在使用 wxWidgets,并强烈推荐它用于 C++ 中的跨平台 GUI 编程,根据 wxWiki 图形页面 Numerix 图形库可用于实时数据,因此也许可以帮助您。 祝你好运。

I do not have any personal experience with wxMathPlot, but I have been working with wxWidgets for years and highly recommend it for cross platform gui programming in c++, with that said according to the wxWiki graphics page the Numerix Graphics Library can be used for real time data so maybe that can help you out. Good luck.

得不到的就毁灭 2024-07-30 09:49:03

也许有人会遇到同样的问题并且需要它......我需要非常快速的绘图来显示示波器的数据。
我正在以数据包的形式获取数据。 我做了一些更改,使代码快了很多
首先是将函数 SetData 中的 if 状态从 if (xs.size()>0) 更改为 if (!xs.empty)代码>.
然后,您应该首先将所有数据包添加到向量中

Vector1_X.push_back(x);
Vector1_Y.push_back(y);

,然后您应该拟合并设置数据。

Vector1 ->SetData(Vector1_X,Vector1_Y); // add vectors to main vector
MathPlot1-> Fit(); //fit plot to the data
Vector1_X.clear(); //if you want to clear plot after every packet 
Vector1_Y.clear(); //you should use it

主函数中的代码会更长,但函数会更快,因为您“一次”添加所有数据。

Maybe someone will have same problem and will need it... I needed very fast plotting for showing the data from oscilloscope.
I was getting the data in packets. I made few changes that made a code a lot of faster.
First thing is to change the if state in function SetData from if (xs.size()>0) to if (!xs.empty).
Then you should firstly add all of your data packet to the vector

Vector1_X.push_back(x);
Vector1_Y.push_back(y);

And after that you should fit and set data.

Vector1 ->SetData(Vector1_X,Vector1_Y); // add vectors to main vector
MathPlot1-> Fit(); //fit plot to the data
Vector1_X.clear(); //if you want to clear plot after every packet 
Vector1_Y.clear(); //you should use it

Your code in main function will be longer but function will be faster because you add all data "at once".

蘑菇王子 2024-07-30 09:49:03

我们最终使用 ChartDirector 代替。 它具有很多功能并且速度很快。

We ended up using ChartDirector instead. It has a lot of capability and is fast.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文