Strange extra line in my plotting, help please
Hi everyone,
I am new to the Qwt. I need to plot a curve against time. Here is my code:
Code:
int plotSize = 100;
int timeCnt = 0;
void cycleScrDialog::setPlot()
{
// create a plot
// add curves
curveT
->setPen
(QPen(Qt
::red,
1));
curveT->attach(ui->qwtPlot);
curveP
->setPen
(QPen(Qt
::blue,
1));
curveP->attach(ui->qwtPlot);
// add Axis
ui
->qwtPlot
->setAxisScale
(QwtPlot::xBottom,
0,
100);
ui
->qwtPlot
->setAxisScale
(QwtPlot::yLeft,
-1,
1);
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = 0;
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
}
void cycleScrDialog::timerEvent() // timer generates event every 1/4 second
{
if (timeCnt < plotSize)
{
x[timeCnt] = timeCnt;
yT[timeCnt] = sin(timeCnt * 0.25);
yP[timeCnt] = cos(timeCnt * 0.5);
ui->qwtPlot->replot();
timeCnt ++;
}
else
timeCnt = 0;
}
I have two questions here:
1. when i run the program, it is plotting a straight line between the (0,0) and new plot dot coordinate.
http://i53.tinypic.com/3450ljm.jpg
I have read through this forum. but i didn't anyone get the same problem.
2. I can resize the axis font. However, I can't find a way to resize the axis itself (in green area). I wonder the axis size is fixed, and cannot be changed. Am I right?
http://i52.tinypic.com/w1tmo4.jpg
Can anyone give me a hint, please?
Thanks in advance.
Re: Strange extra line in my plotting, help please
1) Obviously there is a (0, 0) at the end of your data left from the initialization
2) plotLayout()->setAlignCanvasToScales(true);
Uwe
Re: Strange extra line in my plotting, help please
Hi Uwe,
Thanks for your kind reply.
1) You can see I want to plot temperature and pressure data against time. I have tried different code. But I either got curve1 or curve2
http://i56.tinypic.com/qqs4us.jpg
curve 1
http://i51.tinypic.com/qpry1k.jpg
curve 2
the code for curve1:
Code:
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = 0;
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
code for curve 2
Code:
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = i; // here is the only difference
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
it looks like it always links to next data (initialized data) when it plotting the last data. Can do I get rid of last plotting data, then it will look like:
http://i51.tinypic.com/2ce10cn.jpg
2) to resize the scale, i changed my code as follow. However, no matter how do I changed the “int margin†value, I didn't see any changed of the scale. Could you please give me some advice about my code?
Code:
void cycleScrDialog::setPlot()
{
// create plot
// resize scale
layout->setAlignCanvasToScales(false);
layout->setCanvasMargin(2,-1);
// add curves
curveT
->setPen
(QPen(Qt
::red,
1));
curveT->attach(ui->qwtPlot);
curveP
->setPen
(QPen(Qt
::blue,
1));
curveP->attach(ui->qwtPlot);
// add Axis
ui
->qwtPlot
->setAxisScale
(QwtPlot::xBottom,
0,
100);
ui
->qwtPlot
->setAxisScale
(QwtPlot::yLeft,
-1,
1);
Thanks a lot :)
Re: Strange extra line in my plotting, help please
The margin has no effect, when you align the scales to the canvas.
Uwe
Re: Strange extra line in my plotting, help please
Hi Uwe,
Thanks for your reply.
Do you have any idea about the extra straight line in the end of curve?
Thanks a lot
Re: Strange extra line in my plotting, help please
I solved the first problem, but i think i did it in hard way. if anyone would point me a good and right way, i will be really appreciate.
here is my code:
Code:
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
curveT->setRawData(x,yT,chartCnt); // here is the point
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
Uwe,
I am not quite clear about your reply.
in your first reply, you said:
Quote:
plotLayout()->setAlignCanvasToScales(true);
I though i need to use setAlignCanvasToScales(true) to achieve it.
but in your second reply, you told me
Quote:
The margin has no effect, when you align the scales to the canvas.
do you mind give me some code please?
Thank you very much
Re: Strange extra line in my plotting, help please
You need to understand the meaning of the different layout options - no code.
Uwe
Re: Strange extra line in my plotting, help please
thanks Uwe, i will read the qwt layout class again.
Re: Strange extra line in my plotting, help please
Hi Uwe,
I have tried the plotLayout()->setAlignCanvasToScales. Here is my code:
Code:
ui->qwtPlot->plotLayout()->setAlignCanvasToScales(false);
ui->qwtPlot->plotLayout()->setCanvasMargin(50, -1);
I got this:
http://i54.tinypic.com/jg4f9s.jpg
the length of the scale backbone has been shorted.
What i really want is to make the scale backbone skinner. The reason is that the screen what i am running my application is only 4.3". I need get more space to display the chart. Therefore, i want to save some scale backbone space (even a little bit) to my chart. I wish the scale backbone will be looks like:
http://i52.tinypic.com/6xubsj.jpg
Is that possible to achieve? Thanks for your help.
Re: Strange extra line in my plotting, help please
Maybe plot->axisWidget(...)->setMargin(0); is what you want. You can also save some pixels by reducing the spacing and you could disable the frame of the canvas. Another idea is to disable the left axis completely and to insert a QwtPlotScaleItem on the canvas instead.
Uwe
Re: Strange extra line in my plotting, help please
Thanks Uwe,
after i setup "setMargin(0)" and disable the frame of canvas, I got saved some pixels in my plotting screen.
Thank for your help