简体   繁体   English

用Qwt绘制半对数图

[英]Plotting a semilog chart with Qwt

I would like to plot a semilog chart using Qwt. 我想使用Qwt绘制一个半对数图。 I have not knowledge about Qwt but I was looking for some examples to guide my code. 我不了解Qwt,但是我正在寻找一些示例来指导我的代码。 The problem is that at the moment I don't find someone. 问题是,目前我找不到人。 Could you help me with a simple code? 您能帮我一个简单的代码吗? I want to use a matrix where I can get the x-axis and y-axis values and use them to create the plot. 我想使用一个矩阵,在该矩阵中我可以获取x轴和y轴值,并使用它们创建绘图。 Thank you! 谢谢!

Try this: 尝试这个:

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);

I used here QVector but qwtplotcurve support double arrays and other things, but I like work with containers. 我在这里使用了QVector,但是qwtplotcurve支持双精度数组和其他东西,但是我喜欢使用容器。 You can choose the best for you. 您可以选择最适合自己的。 QPoint contains x and y values. QPoint包含x和y值。

Qwt also offer logarithmic scale engine: http://qwt.sourceforge.net/class_qwt_log_scale_engine.html Qwt还提供对数比例引擎: http : //qwt.sourceforge.net/class_qwt_log_scale_engine.html

I should to say that maybe something wrong with your Qwt, but next code works perfectly on my computer: 我应该说您的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();
}

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM