C++ 用Qwt绘制半对数图

C++ 用Qwt绘制半对数图,c++,c++11,plot,qt5,qwt,C++,C++11,Plot,Qt5,Qwt,我想用Qwt绘制一个半对数图。我不知道Qwt,但我正在寻找一些例子来指导我的代码。问题是目前我找不到人。你能帮我写一个简单的代码吗?我想使用一个矩阵,在这里我可以得到x轴和y轴的值,并使用它们来创建绘图。谢谢大家! 试试这个: QwtPlot *myPlot = new QwtPlot; QwtPlotCurve *curve1 = new QwtPlotCurve;   QwtPointSeriesData* myData = new QwtPointSeriesData;   Q

我想用Qwt绘制一个半对数图。我不知道Qwt,但我正在寻找一些例子来指导我的代码。问题是目前我找不到人。你能帮我写一个简单的代码吗?我想使用一个矩阵,在这里我可以得到x轴和y轴的值,并使用它们来创建绘图。谢谢大家!

试试这个:

QwtPlot *myPlot = new QwtPlot;
  QwtPlotCurve *curve1 = new QwtPlotCurve;
 
  QwtPointSeriesData* myData = new QwtPointSeriesData;
 
  QVector<QPointF>* samples = new QVector<QPointF>;
  samples->push_back(QPointF(1.0,1.0));
  samples->push_back(QPointF(2.0,2.0));
  samples->push_back(QPointF(3.0,3.0));
  samples->push_back(QPointF(4.0,5.0));
  myData->setSamples(*samples);
  curve1->setData(myData);
 
  curve1->attach(myPlot);
QwtPlot*myPlot=新的QwtPlot;
QwtPlotCurve*curve1=新的QwtPlotCurve;
 
QwtPointSeriesData*myData=新的QwtPointSeriesData;
 
QVector*样本=新的QVector;
样本->推回(QPointF(1.0,1.0));
样本->推回(QPointF(2.0,2.0));
样本->推回(QPointF(3.0,3.0));
样本->推回(QPointF(4.0,5.0));
myData->setSamples(*样本);
曲线1->设置数据(myData);
 
曲线1->附加(myPlot);
我在这里使用QVector,但qwtplotcurve支持双数组和其他东西,但我喜欢使用容器。你可以为自己选择最好的。QPoint包含x和y值

Qwt还提供对数刻度引擎:

我想说的是,也许你的Qwt有问题,但下一个代码在我的电脑上运行得很好:

#include "mainwindow.h"
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>

int main(int argc, char *argv[])
{
      QApplication a(argc, argv);
      QwtPlot *myPlot = new QwtPlot;
      QwtPlotCurve *curve1 = new QwtPlotCurve;

      QwtPointSeriesData* myData = new QwtPointSeriesData;

      QVector<QPointF>* samples = new QVector<QPointF>;
      samples->push_back(QPointF(1.0,1.0));
      samples->push_back(QPointF(2.0,2.0));
      samples->push_back(QPointF(3.0,3.0));
      samples->push_back(QPointF(4.0,5.0));
      myData->setSamples(*samples);
      curve1->setData(myData);

      curve1->attach(myPlot);
      myPlot->show();
//    MainWindow w;
//    w.show();

    return a.exec();
}
#包括“mainwindow.h”
#包括
#包括
#包括
int main(int argc,char*argv[])
{
质量保证申请a(argc、argv);
QwtPlot*myPlot=新的QwtPlot;
QwtPlotCurve*curve1=新的QwtPlotCurve;
QwtPointSeriesData*myData=新的QwtPointSeriesData;
QVector*样本=新的QVector;
样本->推回(QPointF(1.0,1.0));
样本->推回(QPointF(2.0,2.0));
样本->推回(QPointF(3.0,3.0));
样本->推回(QPointF(4.0,5.0));
myData->setSamples(*样本);
曲线1->设置数据(myData);
曲线1->附加(myPlot);
myPlot->show();
//主窗口w;
//w.show();
返回a.exec();
}

请澄清。你想用对数标度绘图还是像MathCad那样只绘制矩阵(2xN)?@Chernobyl我更正了它。我希望能有所帮助:)我加了“包括”和“包括”。然后我把你的代码复制到一个主函数,我的程序意外地完成了。有什么想法吗?我的IDE配置了Qwt。@请看我的编辑,这段代码运行得很好,不幸的是,您的Qt/Qwt似乎有问题