1 Attachment(s)
QwtPolarPlot radius scale
Hello,
I'm looking for how to create my own major and minor ticks on the scaleId
QwtPolar::Radius.
I tried :
Code:
if (!d_prefDlg->get_pasZ_Auto()) {
/* Récupération du pas choisi
****************************/
double pasz = d_prefDlg->get_pasZ();
/* Ajustement des extrema
************************/
nivmax = pasz*ceil(nivmax/pasz);
nivmin = pasz*floor(nivmin/pasz);
/* Nombre de pas
***************/
double nbPas = ((int)(((nivmax-nivmin)/pasz)));
/* Recherche du meilleur pas principal
*************************************/
double major;
for(int ii=8; ii>1; ii--) {
major = floor(nbPas/ii);
if (major > 5)
break;
}
double pasMajor = major*pasz;
int nbPasminor = floor(pasMajor/pasz);
d_polarplot->setScale(QwtPolar::Radius,nivmin, nivmax, pasMajor);
d_polarplot->setScaleMaxMajor(QwtPolar::Radius, major);
d_polarplot->setScaleMaxMinor(QwtPolar::Radius, nbPasminor);
/* Création des pas principaux et secondaires
********************************************/
QList<double>
&majorTicksR
= ticksR
[QwtScaleDiv::MajorTick];
QList<double>
&minorTicksR
= ticksR
[QwtScaleDiv::MinorTick];
for (double niveau=nivmin; niveau <= nivmax; niveau=niveau+pasz) {
if (fmod((niveau-nivmin),major*pasz) == 0) {
majorTicksR.append(niveau);
} else {
minorTicksR.append(niveau);
}
}
majorTicksR.last(), ticksR);
d_polarplot->setScaleDiv(QwtPolar::Radius, myScaleDivR);
if (d_polarplot->scaleDiv(QwtPolar::Radius)->isValid() == false)
Message("Invalide", false);
} else
d_polarplot->setScale(QwtPolar::Radius,nivmin, nivmax);
With nivmin = -93, nivmax=-39 and pasz=3, I should get the following major
ticks :-93,-75,-57 and -39, with 6 minor ticks between 2 major ticks.
But that did'nt work (see attach file).
Thanks for your help
Re: QwtPolarPlot radius scale
The boundaries and all major and minor ticks of a scale are defined in a QwtScaleDiv object. You can calculate a QwtScaleDiv object in your application code and pass it to the plot using QwtPolarPlot::setScaleDiv().
A plot widget has a scale engine for each scale, that is able to calculate a QwtScaleDiv object from min/max/stepsize ( + max major steps + max minor steps ). QwtPolarPlot::setScale() calculates internally a QwtScaleDiv using the internal scale engine.
Qwt offers two different types of scale engines: a linear and logarithmic one, both based on decades.
The right solution for your problem depends on whether your plot offers a navigation ( zooming, panning, ... ). If not you can manually calculate your ticks and use QwtPolarPlot::setScaleDiv() - not using the internal scale engine.
But if your plot offers navigation you need to implement an algorithm, that calculates ticks for any random boundaries for your -93 +i * 18 based scale system ( what ticks do you expect from a range -90 -> -89 ? ) in a class derived from QwtScaleEngine.
Uwe
Re: QwtPolarPlot radius scale (resolved)
Hello,
I resolved my problem. The QwtPolar documentation indicates that using setScaleDiv the autoscalling is disabled, but in fact you should disable the autoscaling in the QwtPolarGrid:
Code:
this->d_grid = new QwtPolarGrid();
if (!d_prefDlg->get_pasZ_Auto())
d_grid->setGridAttribute(QwtPolarGrid::AutoScaling,false);
else
d_grid->setGridAttribute(QwtPolarGrid::AutoScaling,true);
....
d_grid->attach(d_polarplot);
Thank a lot