PDA

View Full Version : Problem with scatter plot, refreshing, animating and zooming.



breotone
6th October 2011, 22:48
Hello,

My purpose is to show a graphical representation of a RAW data from a 3-axis accelerometer. For this, I read the RAW data file and get the information into a typedef structure. This raw data is downsampled to 1 sample per second for handle it in a fast way.

The goal is to show a period of time requiered from a main window, and animate this plot with a vertical bar, for play like in real time, in order to follow the data showed.

For this I need to plot a specific period of time and label it as well.

I could do it, but I found several problems. I really would appreciate if somebody can help me, even with just one of them....

1. Y-Axis. When I plot, the scale in the y-axis is not correct, it doesn't appear anything until i move the mouse wheel (zoom). With just moving the zoom, it is looking correct in the y-axis.

6942


2. X-Axis. I have to plot information of a period of time (ex, from 1pm to 2pm). After plotting, it is not exactly correct. It shows like from 1:05 to 1:55, and I need to zoom out one time for the correct adjustment.

6943

6944

3. After closing one window with the plot, and trying to plot a different period of time, in the legend, appears the new and the old functions for plotting... and they don't work well, I mean, if I tick one of them, disappears part of the function, not all of it.

6945

4. When I can solve the problems above, I would like to animate it with a vertical bar, any suggestion about it?

Thanks in advance!

Uwe
7th October 2011, 08:25
1. Y-Axis. When I plot, the scale in the y-axis is not correct, ...

What do you mean by plot - and how do you set your y-axis ?



2. X-Axis. I have to plot information of a period of time (ex, from 1pm to 2pm). After plotting, it is not exactly correct. It shows like from 1:05 to 1:55, and I need to zoom out one time for the correct adjustment.
As you don't seem to have an idea how you get your scales I guess you are using autoscaling. Use QwtPlot::setAxisScale or even QwtPlot::setAxisScaleDiv() instead.



3. After closing one window with the plot, and trying to plot a different period of time, in the legend, appears the new and the old functions for plotting... and they don't work well, I mean, if I tick one of them, disappears part of the function, not all of it..
A bug in your code - you didn't remove the previous curves before you insert the new ones.


4. When I can solve the problems above, I would like to animate it with a vertical bar, any suggestion about it?
Be careful with such a feature:

It is possible to paint incrementally ( QwtPlotDirectPainter ), but it is not possible to erase something without having to replot. So when you have many points and you want to update with high frame rates such a bar might be a performance issue, when you don't understand how rendering works in detail.

Uwe

breotone
7th October 2011, 15:43
Hi Uwe, thanks a lot for your reply!

1. This is my code for the y-axis scale. It is fitting this range in the window after a movement of zoom out.

setAxisScale( QwtPlot::yLeft, -8.5, 8.5 );
setAxisTitle( QwtPlot::yLeft, "g-force" );


2. This is the code for the x-Axis.

QList<double> ticks[QwtScaleDiv::NTickTypes];
ticks[QwtScaleDiv::MajorTick] << 0 << numberOfSamples;

QwtScaleDiv scaleDiv(
ticks[QwtScaleDiv::MajorTick].first(),
ticks[QwtScaleDiv::MajorTick].last(),
ticks );

setAxisScaleDiv(QwtPlot::xBottom, scaleDiv);
setAxisTitle( QwtPlot::xBottom, " System Uptime [h:m:s]" );

//Axis for drawing with the date with format
setAxisScaleDraw( QwtPlot::xBottom, new TimeScaleDraw( this->drawSettings.firstMinute ) );
setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );

3. And for the legend:

//Clikable LEGEND
QwtLegend *legend = new QwtLegend;
legend->setItemMode( QwtLegend::CheckableItem );
this->insertLegend( legend, QwtPlot::RightLegend );


The main problem can be the architecture I am using. I have an object, with 2 main methods, collecting_data and drawing.

The firs thing to do in my program is collecting the data, and after this, I have a button in a main window for drawing a specific period of time, so maybe when I press close, I should destroy the object, but I can not because the information is in this object... so I have to find a way to refresh the plot with the values I want..

Thanks!