NEW: added possibility to scale the axis ticks by a factor (e.g. pi) to generate axes with ticks 0pi, 1pi, 2pi ...
@ -54,10 +54,11 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
|||||||
<li>NEW: barcharts (derived from JKQTPBarGraphBase) can be configured to use different fill styles above and below the baseline, see JKQTPBarGraphBase::FillMode </li>
|
<li>NEW: barcharts (derived from JKQTPBarGraphBase) can be configured to use different fill styles above and below the baseline, see JKQTPBarGraphBase::FillMode </li>
|
||||||
<li>NEW: added new error indicator styles JKQTPErrorHalfBarsOutwards, JKQTPErrorHalfBarsInwards, JKQTPErrorHalfBarsAbove, JKQTPErrorHalfBarsBelow which are especially useful for barcharts</li>
|
<li>NEW: added new error indicator styles JKQTPErrorHalfBarsOutwards, JKQTPErrorHalfBarsInwards, JKQTPErrorHalfBarsAbove, JKQTPErrorHalfBarsBelow which are especially useful for barcharts</li>
|
||||||
<li>NEW: Added signals JKQTBasePlotter::beforeExporting()/JKQTBasePlotter::afterExporting() and JKQTBasePlotterJKQTBasePlotter:beforePrinting()/JKQTBasePlotter::afterPrinting() which allow to modify the plot just before and just after an export/print</li>
|
<li>NEW: Added signals JKQTBasePlotter::beforeExporting()/JKQTBasePlotter::afterExporting() and JKQTBasePlotterJKQTBasePlotter:beforePrinting()/JKQTBasePlotter::afterPrinting() which allow to modify the plot just before and just after an export/print</li>
|
||||||
<li>NEW: Added new JKQTPCALabelType elements (JKQTPCALTfrac...), so axis label ticks can be displayed as fractions 1/2 instead of 0.5</li>
|
<li>NEW: Added new JKQTPCALabelType elements (JKQTPCALTfrac...), so axis label ticks can be displayed as fractions 1/2 instead of 0.5<br>
|
||||||
<li>NEW: Added new JKQTPCALabelType elements JKQTPCALTscientific, so axis label ticks can be displayed as numbers in scientific notation like \c 1.2E-34<br>
|
JKQTPCALTscientific, so axis label ticks can be displayed as numbers in scientific notation like \c 1.2E-34<br>
|
||||||
JKQTPCALTprintf for general formatting with a printf-format string </li>
|
JKQTPCALTprintf for general formatting with a printf-format string </li>
|
||||||
<li>NEW: all elements of a coordinate axis may have their own color now </li>
|
<li>NEW: all elements of a coordinate axis may have their own color now </li>
|
||||||
|
<li>NEW: added possibility to scale the axis ticks by a factor (e.g. pi) to generate axes with ticks <tt>0pi, 1pi, 2pi ...</tt> </li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
|
|
||||||
<li>JKQTMathText:<ul>
|
<li>JKQTMathText:<ul>
|
||||||
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.8 KiB |
BIN
doc/images/axisstyle/JKQTPLTMLin.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
doc/images/axisstyle/JKQTPLTMLinOrPower.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
doc/images/axisstyle/JKQTPLTMPower.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
doc/images/axisstyle/axis_unit_scaling_none.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
doc/images/axisstyle/axis_unit_scaling_pi.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.9 KiB |
@ -424,7 +424,7 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief return x coordinate coordinate from x-pixel */
|
/** \brief return x coordinate from x-pixel */
|
||||||
inline double p2x(long x) {
|
inline double p2x(long x) {
|
||||||
if (xAxisLog) {
|
if (xAxisLog) {
|
||||||
return exp(JKQTPSTATISTICS_LN10*(static_cast<double>(x)-xOffset)/(xScale));
|
return exp(JKQTPSTATISTICS_LN10*(static_cast<double>(x)-xOffset)/(xScale));
|
||||||
@ -443,7 +443,7 @@ class JKQTFASTPLOTTER_LIB_EXPORT JKQTFastPlotter :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief return y coordinate coordinate from y-pixel */
|
/** \brief return y coordinate from y-pixel */
|
||||||
inline double p2y(long y) {
|
inline double p2y(long y) {
|
||||||
if (yAxisLog) {
|
if (yAxisLog) {
|
||||||
return exp(JKQTPSTATISTICS_LN10*(static_cast<double>(y)-yOffset)/(-1.0*yScale));
|
return exp(JKQTPSTATISTICS_LN10*(static_cast<double>(y)-yOffset)/(-1.0*yScale));
|
||||||
|
@ -585,7 +585,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
|
|||||||
/** \brief clear all additional plotters for grid printing mode */
|
/** \brief clear all additional plotters for grid printing mode */
|
||||||
void clearGridPrintingPlotters();
|
void clearGridPrintingPlotters();
|
||||||
|
|
||||||
/** \brief return x-pixel coordinate from time coordinate */
|
/** \brief return x-pixel coordinate from x coordinate */
|
||||||
inline double x2p(double x) const {
|
inline double x2p(double x) const {
|
||||||
return xAxis->x2p(x);
|
return xAxis->x2p(x);
|
||||||
}
|
}
|
||||||
@ -595,12 +595,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
|
|||||||
return yAxis->x2p(y);
|
return yAxis->x2p(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief return time coordinate coordinate from x-pixel */
|
/** \brief return x coordinate from x-pixel */
|
||||||
inline double p2x(double x) const {
|
inline double p2x(double x) const {
|
||||||
return xAxis->p2x(x);
|
return xAxis->p2x(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief return y coordinate coordinate from y-pixel */
|
/** \brief return y coordinate from y-pixel */
|
||||||
inline double p2y(double y) const {
|
inline double p2y(double y) const {
|
||||||
return yAxis->p2x(y);
|
return yAxis->p2x(y);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ JKQTPCoordinateAxis::JKQTPCoordinateAxis(JKQTBasePlotter* _parent):
|
|||||||
tickSpacing(0),
|
tickSpacing(0),
|
||||||
tickSpacingLog(10),
|
tickSpacingLog(10),
|
||||||
axisLabel(),
|
axisLabel(),
|
||||||
|
tickUnitFactor(1),
|
||||||
|
tickUnitName(""),
|
||||||
axisPrefix(),
|
axisPrefix(),
|
||||||
scaleSign(1)
|
scaleSign(1)
|
||||||
{
|
{
|
||||||
@ -403,17 +405,28 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
|
|||||||
belowIsZero=fabs(getMax()-getMin())*1e-6;
|
belowIsZero=fabs(getMax()-getMin())*1e-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data=data/tickUnitFactor;
|
||||||
|
|
||||||
|
auto addTickUnit=[&](const QString& s) {
|
||||||
|
if (tickUnitName.isEmpty()) return s;
|
||||||
|
bool ok=false;
|
||||||
|
const double d=s.toDouble(&ok);
|
||||||
|
if (s=="0" || (ok && fabs(d)<1e-300)) return s;
|
||||||
|
if (s=="1" || (ok && d==1.0)) return tickUnitName;
|
||||||
|
return s+tickUnitName;
|
||||||
|
};
|
||||||
|
|
||||||
switch(axisStyle.tickLabelType) {
|
switch(axisStyle.tickLabelType) {
|
||||||
case JKQTPCALTcount:
|
case JKQTPCALTcount:
|
||||||
return "";
|
return "";
|
||||||
case JKQTPCALTdefault:
|
case JKQTPCALTdefault:
|
||||||
return floattostringWithFormat(loc, data, 'f', past_comma, remove_trail0);
|
return addTickUnit(floattostringWithFormat(loc, data, 'f', past_comma, remove_trail0));
|
||||||
case JKQTPCALTscientific:
|
case JKQTPCALTscientific:
|
||||||
return floattostringWithFormat(loc, data, 'e', past_comma, remove_trail0);
|
return addTickUnit(floattostringWithFormat(loc, data, 'e', past_comma, remove_trail0));
|
||||||
case JKQTPCALTexponent:
|
case JKQTPCALTexponent:
|
||||||
return QString(jkqtp_floattolatexstr(data, past_comma, remove_trail0, belowIsZero, pow(10, -past_comma), pow(10, past_comma+1)).c_str());
|
return addTickUnit(QString(jkqtp_floattolatexstr(data, past_comma, remove_trail0, belowIsZero, pow(10, -past_comma), pow(10, past_comma+1)).c_str()));
|
||||||
case JKQTPCALTexponentCharacter:
|
case JKQTPCALTexponentCharacter:
|
||||||
return QString(jkqtp_floattolatexunitstr(data, past_comma, remove_trail0).c_str());
|
return addTickUnit(QString(jkqtp_floattolatexunitstr(data, past_comma, remove_trail0).c_str()));
|
||||||
case JKQTPCALTintfrac:
|
case JKQTPCALTintfrac:
|
||||||
case JKQTPCALTintsfrac:
|
case JKQTPCALTintsfrac:
|
||||||
case JKQTPCALTintslashfrac:
|
case JKQTPCALTintslashfrac:
|
||||||
@ -443,16 +456,21 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
|
|||||||
if (num!=0) {
|
if (num!=0) {
|
||||||
if (denom==1) res+=QString::number(num);
|
if (denom==1) res+=QString::number(num);
|
||||||
else {
|
else {
|
||||||
if (axisStyle.tickLabelType==JKQTPCALTfrac || axisStyle.tickLabelType==JKQTPCALTintfrac) res+=QString("\\frac{%1}{%2}").arg(num).arg(denom);
|
if (axisStyle.tickLabelType==JKQTPCALTfrac || (axisStyle.tickLabelType==JKQTPCALTintfrac && intpart==0)) res+=QString("\\frac{%1}{%2}").arg(addTickUnit(QString::number(num))).arg(denom);
|
||||||
else if (axisStyle.tickLabelType==JKQTPCALTsfrac || axisStyle.tickLabelType==JKQTPCALTintsfrac) res+=QString("\\sfrac{%1}{%2}").arg(num).arg(denom);
|
else if (axisStyle.tickLabelType==JKQTPCALTintfrac) res=addTickUnit(res+QString("\\frac{%1}{%2}").arg(num).arg(denom));
|
||||||
|
else if (axisStyle.tickLabelType==JKQTPCALTsfrac || (axisStyle.tickLabelType==JKQTPCALTintsfrac && intpart==0)) res+=QString("\\sfrac{%1}{%2}").arg(addTickUnit(QString::number(num))).arg(denom);
|
||||||
|
else if (axisStyle.tickLabelType==JKQTPCALTintsfrac) res=addTickUnit(res+QString("\\sfrac{%1}{%2}").arg(num).arg(denom));
|
||||||
else {
|
else {
|
||||||
if (res.size()>0 && res[res.size()-1].isDigit()) {
|
if (res.size()>0 && res[res.size()-1].isDigit()) {
|
||||||
if (sign<0) res+="-";
|
if (sign<0) res+="-";
|
||||||
else res+="+";
|
else res+="+";
|
||||||
}
|
}
|
||||||
res+=QString("%1/%2").arg(num).arg(denom);
|
if (axisStyle.tickLabelType==JKQTPCALTintslashfrac)
|
||||||
|
res=addTickUnit("("+res+QString("%1/%2").arg(num).arg(denom)+")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
res=addTickUnit(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//std::cout<<data<<" => "<<rounded<<", "<<res.toStdString()<<"\n";
|
//std::cout<<data<<" => "<<rounded<<", "<<res.toStdString()<<"\n";
|
||||||
@ -474,7 +492,7 @@ QString JKQTPCoordinateAxis::floattolabel(double data, int past_comma) const {
|
|||||||
return dt.toString(axisStyle.tickDateTimeFormat);
|
return dt.toString(axisStyle.tickDateTimeFormat);
|
||||||
}; break;
|
}; break;
|
||||||
case JKQTPCALTprintf: {
|
case JKQTPCALTprintf: {
|
||||||
return QString::asprintf(axisStyle.tickPrintfFormat.toLatin1().data(), data);
|
return QString::asprintf(axisStyle.tickPrintfFormat.toLatin1().data(), data, tickUnitName.toStdString().c_str());
|
||||||
}; break;
|
}; break;
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
@ -578,14 +596,16 @@ void JKQTPCoordinateAxis::calcPlotScaling(bool force) {
|
|||||||
// autoscaling for the logarithmic plots available
|
// autoscaling for the logarithmic plots available
|
||||||
if (axisStyle.tickMode==JKQTPLTMLinOrPower) {
|
if (axisStyle.tickMode==JKQTPLTMLinOrPower) {
|
||||||
if (logAxis) {
|
if (logAxis) {
|
||||||
tickSpacing=1;
|
tickSpacing=tickUnitFactor;
|
||||||
tickSpacingLog=calcLogTickSpacing();
|
tickSpacingLog=calcLogTickSpacing();
|
||||||
tickStart=pow(logAxisBase, floor(log(axismin)/log(logAxisBase)));
|
tickStart=pow(logAxisBase, floor(log(axismin/tickUnitFactor)/log(logAxisBase)))*tickUnitFactor;
|
||||||
} else {
|
} else {
|
||||||
if (autoAxisSpacing) {
|
if (autoAxisSpacing) {
|
||||||
// autoscaling linear x-axis
|
// autoscaling linear x-axis
|
||||||
tickSpacingLog=10;
|
tickSpacingLog=10.0;
|
||||||
tickSpacing=calcLinearTickSpacing();
|
width/=tickUnitFactor;
|
||||||
|
tickSpacing=calcLinearTickSpacing()*tickUnitFactor;
|
||||||
|
width*=tickUnitFactor;
|
||||||
} else {
|
} else {
|
||||||
// predefined scaling for linear x-axis
|
// predefined scaling for linear x-axis
|
||||||
tickSpacing=userTickSpacing;
|
tickSpacing=userTickSpacing;
|
||||||
@ -596,8 +616,10 @@ void JKQTPCoordinateAxis::calcPlotScaling(bool force) {
|
|||||||
} else if (axisStyle.tickMode==JKQTPLTMLin) {
|
} else if (axisStyle.tickMode==JKQTPLTMLin) {
|
||||||
if (autoAxisSpacing) {
|
if (autoAxisSpacing) {
|
||||||
// autoscaling linear x-axis
|
// autoscaling linear x-axis
|
||||||
tickSpacingLog=10;
|
tickSpacingLog=10.0;
|
||||||
tickSpacing=calcLinearTickSpacing();
|
width/=tickUnitFactor;
|
||||||
|
tickSpacing=calcLinearTickSpacing()*tickUnitFactor;
|
||||||
|
width*=tickUnitFactor;
|
||||||
} else {
|
} else {
|
||||||
// predefined scaling for linear x-axis
|
// predefined scaling for linear x-axis
|
||||||
tickSpacing=userTickSpacing;
|
tickSpacing=userTickSpacing;
|
||||||
@ -605,12 +627,11 @@ void JKQTPCoordinateAxis::calcPlotScaling(bool force) {
|
|||||||
}
|
}
|
||||||
tickStart=floor(axismin/(tickSpacing))*tickSpacing;
|
tickStart=floor(axismin/(tickSpacing))*tickSpacing;
|
||||||
} else if (axisStyle.tickMode==JKQTPLTMPower) {
|
} else if (axisStyle.tickMode==JKQTPLTMPower) {
|
||||||
tickSpacing=1;
|
tickSpacing=1.0*tickUnitFactor;
|
||||||
tickSpacingLog=calcLogTickSpacing();
|
tickSpacingLog=calcLogTickSpacing();
|
||||||
tickStart=pow(logAxisBase, floor(log(axismin)/log(logAxisBase)));
|
tickStart=pow(logAxisBase, floor(log(axismin/tickUnitFactor)/log(logAxisBase)))*tickUnitFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
axisStyle.labelDigits=calcLinearUnitDigits();
|
axisStyle.labelDigits=calcLinearUnitDigits();
|
||||||
#ifdef SHOW_JKQTPLOTTER_DEBUG
|
#ifdef SHOW_JKQTPLOTTER_DEBUG
|
||||||
//qDebug()<<" tickStart="<<tickStart<<"\n";
|
//qDebug()<<" tickStart="<<tickStart<<"\n";
|
||||||
@ -774,6 +795,38 @@ void JKQTPCoordinateAxis::setAxisLabel(const QString& __value) {
|
|||||||
redrawPlot();
|
redrawPlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JKQTPCoordinateAxis::setTickUnitName(const QString &__value)
|
||||||
|
{
|
||||||
|
this->tickUnitName = __value;
|
||||||
|
this->paramsChanged=true;
|
||||||
|
redrawPlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPCoordinateAxis::setTickUnitFactor(double __value)
|
||||||
|
{
|
||||||
|
this->tickUnitFactor = __value;
|
||||||
|
this->paramsChanged=true;
|
||||||
|
redrawPlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPCoordinateAxis::setTickUnit(double factor, const QString &name)
|
||||||
|
{
|
||||||
|
this->tickUnitFactor = factor;
|
||||||
|
this->tickUnitName = name;
|
||||||
|
this->paramsChanged=true;
|
||||||
|
redrawPlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPCoordinateAxis::setTickUnitPi()
|
||||||
|
{
|
||||||
|
setTickUnit(JKQTPSTATISTICS_PI, "\\;\\pi");
|
||||||
|
}
|
||||||
|
|
||||||
|
void JKQTPCoordinateAxis::resetTickUnit()
|
||||||
|
{
|
||||||
|
setTickUnit(1, "");
|
||||||
|
}
|
||||||
|
|
||||||
void JKQTPCoordinateAxis::setLabelPosition(JKQTPLabelPosition __value) {
|
void JKQTPCoordinateAxis::setLabelPosition(JKQTPLabelPosition __value) {
|
||||||
this->axisStyle.labelPosition = __value;
|
this->axisStyle.labelPosition = __value;
|
||||||
this->paramsChanged=true;
|
this->paramsChanged=true;
|
||||||
|
@ -41,7 +41,7 @@ class JKQTBasePlotter;
|
|||||||
|
|
||||||
This class implements all the functionality needed for a coordinate axis:
|
This class implements all the functionality needed for a coordinate axis:
|
||||||
- transform world to screen coordinates and vice versa
|
- transform world to screen coordinates and vice versa
|
||||||
- draw the axis (implemented by child classes!) with these elements: axis lines, JKQTPCoordinateAxisStyle::ticks, tick labels, axis label, x/y=0 axis
|
- draw the axis (implemented by child classes!) with these elements: axis lines, ticks, tick labels, axis label, x/y=0 axis
|
||||||
- measure the axes in screen coordinates
|
- measure the axes in screen coordinates
|
||||||
- load and save the settings to an ini file
|
- load and save the settings to an ini file
|
||||||
.
|
.
|
||||||
@ -115,12 +115,11 @@ class JKQTBasePlotter;
|
|||||||
\see You can find example here: \ref JKQTPlotterImagePlotQImageRGB and \ref JKQTPlotterImagePlotRGBOpenCV
|
\see You can find example here: \ref JKQTPlotterImagePlotQImageRGB and \ref JKQTPlotterImagePlotRGBOpenCV
|
||||||
|
|
||||||
|
|
||||||
\section jkqtplotter_base_grids_baseelemenets Axis JKQTPCoordinateAxisStyle::Ticks and Grids
|
\section jkqtplotter_base_grids_baseelemenets Axis Ticks and Grids
|
||||||
|
This section explains how this component draws the ticks on coordinate axes and the grids that may be drawn below
|
||||||
This section explains how this component draws the JKQTPCoordinateAxisStyle::ticks on coordinate axes and the grids that may be drawn below
|
|
||||||
the plots. In principle both - grids and axes - are drawn the same way, i.e. with the same step widths. There are
|
the plots. In principle both - grids and axes - are drawn the same way, i.e. with the same step widths. There are
|
||||||
two types of JKQTPCoordinateAxisStyle::ticks and grids: The major and the minor JKQTPCoordinateAxisStyle::ticks/grids. The major JKQTPCoordinateAxisStyle::ticks also show a label that denotes the
|
two types of ticks and grids: The major and the minor ticks/grids. The major ticks also show a label that denotes the
|
||||||
value they represent. Between two major JKQTPCoordinateAxisStyle::ticks the axis shows \a JKQTPCoordinateAxisStyle::minorTicks small JKQTPCoordinateAxisStyle::ticks that are not
|
value they represent. Between two major ticks the axis shows \a JKQTPCoordinateAxisStyle::minorTicks small ticks that are not
|
||||||
accompanied by a label. The next image shows an example of an axis:
|
accompanied by a label. The next image shows an example of an axis:
|
||||||
|
|
||||||
\image html plot_axis_ticksandlabels.png
|
\image html plot_axis_ticksandlabels.png
|
||||||
@ -135,21 +134,36 @@ class JKQTBasePlotter;
|
|||||||
For grids applies the same. There are two grids that are drawn in different styles (often the major grid is drawn
|
For grids applies the same. There are two grids that are drawn in different styles (often the major grid is drawn
|
||||||
thicker and darker than the minor grid).
|
thicker and darker than the minor grid).
|
||||||
|
|
||||||
The minor JKQTPCoordinateAxisStyle::ticks and grid lines are generated automatically, depending in the setting of \a JKQTPCoordinateAxisStyle::minorTicks.
|
The minor ticks and grid lines are generated automatically, depending in the setting of \a JKQTPCoordinateAxisStyle::minorTicks.
|
||||||
These properties give the number of minor JKQTPCoordinateAxisStyle::ticks between two major JKQTPCoordinateAxisStyle::ticks, so if the major JKQTPCoordinateAxisStyle::ticks are at 1,2,3,... and you
|
These properties give the number of minor ticks between two major ticks, so if the major ticks are at 1,2,3,... and you
|
||||||
want minor JKQTPCoordinateAxisStyle::ticks at 1.1, 1.2, 1.3,... then you will have to set \c JKQTPCoordinateAxisStyle::minorTicks=9 as there are nine JKQTPCoordinateAxisStyle::ticks between two major
|
want minor ticks at 1.1, 1.2, 1.3,... then you will have to set \c JKQTPCoordinateAxisStyle::minorTicks=9 as there are nine ticks between two major
|
||||||
JKQTPCoordinateAxisStyle::ticks. So the minor tick spacing is calculated as: \f[ \Delta\mbox{MinorTicks}=\frac{\Delta\mbox{ticks}}{\mbox{minorTicks}+1} \f]
|
ticks. So the minor tick spacing is calculated as: \f[ \Delta\mbox{MinorTicks}=\frac{\Delta\mbox{ticks}}{\mbox{minorTicks}+1} \f]
|
||||||
|
|
||||||
The same applies for logarithmic axes. If the major JKQTPCoordinateAxisStyle::ticks are at 1,10,100,... and you set \c JKQTPCoordinateAxisStyle::minorTicks=9 the program will
|
The same applies for logarithmic axes. If the major ticks are at 1,10,100,... and you set \c JKQTPCoordinateAxisStyle::minorTicks=9 the program will
|
||||||
generate 9 equally spaced minor JKQTPCoordinateAxisStyle::ticks in between, so you have minor JKQTPCoordinateAxisStyle::ticks at 2,3,4,...,11,12,13,... This results in a standard
|
generate 9 equally spaced minor ticks in between, so you have minor ticks at 2,3,4,...,11,12,13,... This results in a standard
|
||||||
logarithmic axis. If you set \c JKQTPCoordinateAxisStyle::minorTicks=1 then you will get minor JKQTPCoordinateAxisStyle::ticks at 5,15,150,...
|
logarithmic axis. If you set \c JKQTPCoordinateAxisStyle::minorTicks=1 then you will get minor ticks at 5,15,150,...
|
||||||
|
|
||||||
\image html plot_logaxis_ticksandlabels.png
|
\image html plot_logaxis_ticksandlabels.png
|
||||||
|
|
||||||
The major tick-tick distances of linear axes may be calculated automatically in a way that the axis shows at least a given
|
The major tick-tick distances of linear axes may be calculated automatically in a way that the axis shows at least a given
|
||||||
number of JKQTPCoordinateAxisStyle::ticks \c JKQTPCoordinateAxisStyle::minTicks. The algorithm takes that tick spacing that will give a number of JKQTPCoordinateAxisStyle::ticks per axis
|
number of ticks \c JKQTPCoordinateAxisStyle::minTicks. The algorithm takes that tick spacing that will give a number of ticks per axis
|
||||||
nearest but \c ">=" to the given \c JKQTPCoordinateAxisStyle::minTicks. The Algorithm is described in detail with the function
|
nearest but \c ">=" to the given \c JKQTPCoordinateAxisStyle::minTicks. The Algorithm is described in detail with the function
|
||||||
calcLinearTickSpacing(). To activate this automatic tick spacing you have to set <code>autoAxisSpacing=true</code>.
|
calcLinearTickSpacing(). To activate this automatic tick spacing you have to set <code>autoAxisSpacing=true</code>.
|
||||||
|
|
||||||
|
\section jkqtplotter_coordinateaxes_tickscaling Axis Tick Units/Scaling
|
||||||
|
In some cases it is desired to put the axis ticks not at 1,2,3,... but rather at \f$ 1\pi \f$ , \f$ 2\pi \f$ , \f$ 3\pi \f$ or any other
|
||||||
|
unit than \f$ pi \f$ ,i.e.:
|
||||||
|
|
||||||
|
\image html axisstyle/axis_unit_scaling_none.png "no axis scaling (default case)"
|
||||||
|
\image html axisstyle/axis_unit_scaling_pi.png "pi-axis scaling (default case)"
|
||||||
|
|
||||||
|
You can use these methods to set such a factor:
|
||||||
|
- setTickUnitFactor() for the actual factor and setTickUnitName() for a name, added to the tick label
|
||||||
|
- setTickUnit() sets factor and name in one call
|
||||||
|
- setTickUnitPi() shortcut to set pi-scaling
|
||||||
|
- resetTickUnit() resets to no-scaling (default case)
|
||||||
|
.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -171,7 +185,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
virtual void saveSettings(QSettings& settings, const QString& group=QString("plots/axes/")) const;
|
virtual void saveSettings(QSettings& settings, const QString& group=QString("plots/axes/")) const;
|
||||||
|
|
||||||
|
|
||||||
/** \brief return x-pixel coordinate from time coordinate */
|
/** \brief return x-pixel coordinate from x coordinate */
|
||||||
inline double x2p(double x) const {
|
inline double x2p(double x) const {
|
||||||
double r=0;
|
double r=0;
|
||||||
if (logAxis) {
|
if (logAxis) {
|
||||||
@ -187,7 +201,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief return time coordinate coordinate from x-pixel */
|
/** \brief return x coordinate from x-pixel */
|
||||||
inline double p2x(double x) const {
|
inline double p2x(double x) const {
|
||||||
double xx=x;
|
double xx=x;
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
@ -253,6 +267,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
inline JKQTPCALabelType getTickLabelType() const { return this->axisStyle.tickLabelType; }
|
inline JKQTPCALabelType getTickLabelType() const { return this->axisStyle.tickLabelType; }
|
||||||
/** \copydoc axisLabel */
|
/** \copydoc axisLabel */
|
||||||
inline QString getAxisLabel() const { return this->axisLabel; }
|
inline QString getAxisLabel() const { return this->axisLabel; }
|
||||||
|
/** \copydoc tickUnitFactor */
|
||||||
|
inline double getTickUnitFactor() const { return this->tickUnitFactor; }
|
||||||
|
/** \copydoc tickUnitName */
|
||||||
|
inline QString getTickUnitName() const { return this->tickUnitName; }
|
||||||
/** \copydoc JKQTPCoordinateAxisStyle::labelPosition */
|
/** \copydoc JKQTPCoordinateAxisStyle::labelPosition */
|
||||||
inline JKQTPLabelPosition getLabelPosition() const { return this->axisStyle.labelPosition; }
|
inline JKQTPLabelPosition getLabelPosition() const { return this->axisStyle.labelPosition; }
|
||||||
/** \copydoc JKQTPCoordinateAxisStyle::labelFontSize */
|
/** \copydoc JKQTPCoordinateAxisStyle::labelFontSize */
|
||||||
@ -465,6 +483,28 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
/** \copydoc axisLabel */
|
/** \copydoc axisLabel */
|
||||||
void setAxisLabel (const QString& __value);
|
void setAxisLabel (const QString& __value);
|
||||||
|
|
||||||
|
/** \copydoc tickUnitName */
|
||||||
|
void setTickUnitName(const QString& __value);
|
||||||
|
|
||||||
|
/** \copydoc tickUnitFactor */
|
||||||
|
void setTickUnitFactor(double __value);
|
||||||
|
/** \brief sets tickUnitFactor and tickUnitName in one call
|
||||||
|
*
|
||||||
|
* \see calls setTickUnitName() and setTickUnitFactor()
|
||||||
|
*/
|
||||||
|
void setTickUnit(double factor, const QString& name);
|
||||||
|
/** \brief sets pi-scaling for tickUnitFactor and tickUnitName in one call
|
||||||
|
*
|
||||||
|
* \image html axisstyle/axis_unit_scaling_pi.png
|
||||||
|
* \see calls setTickUnitName() and setTickUnitFactor()
|
||||||
|
*/
|
||||||
|
void setTickUnitPi();
|
||||||
|
/** \brief resets tickUnitFactor and tickUnitName in one call
|
||||||
|
*
|
||||||
|
* \see calls setTickUnit(), setTickUnitName() and setTickUnitFactor()
|
||||||
|
*/
|
||||||
|
void resetTickUnit();
|
||||||
|
|
||||||
/** \copydoc JKQTPCoordinateAxisStyle::labelPosition */
|
/** \copydoc JKQTPCoordinateAxisStyle::labelPosition */
|
||||||
void setLabelPosition (JKQTPLabelPosition __value);
|
void setLabelPosition (JKQTPLabelPosition __value);
|
||||||
|
|
||||||
@ -627,9 +667,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
QString floattolabel(double data, int past_comma) const;
|
QString floattolabel(double data, int past_comma) const;
|
||||||
/** \brief parent plotter class */
|
/** \brief parent plotter class */
|
||||||
JKQTBasePlotter* parent;
|
JKQTBasePlotter* parent;
|
||||||
/** \brief current view: minimum of time axis */
|
/** \brief current view: minimum of axis */
|
||||||
double axismin;
|
double axismin;
|
||||||
/** \brief current view: maximum of time axis */
|
/** \brief current view: maximum of axis */
|
||||||
double axismax;
|
double axismax;
|
||||||
|
|
||||||
/** \brief absoulte minimum of axis (axismin/axismax xan not be set below this) */
|
/** \brief absoulte minimum of axis (axismin/axismax xan not be set below this) */
|
||||||
@ -647,18 +687,18 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
/** \brief absolute minimum range width, feature switched off when <0 */
|
/** \brief absolute minimum range width, feature switched off when <0 */
|
||||||
double axisMinWidth;
|
double axisMinWidth;
|
||||||
|
|
||||||
/** \brief <b>calculated property:</b> width of plot on time axis (calculated by calcPlotScaling() )
|
/** \brief <b>calculated property:</b> width of plot on axis (calculated by calcPlotScaling() )
|
||||||
*
|
*
|
||||||
* \see calcPlotScaling(), calcTickSpacing()
|
* \see calcPlotScaling(), calcTickSpacing()
|
||||||
*/
|
*/
|
||||||
double width;
|
double width;
|
||||||
|
|
||||||
/** \brief <b>calculated property:</b> time axis scaling factor (calculated by calcPlotScaling() )
|
/** \brief <b>calculated property:</b> axis scaling factor (calculated by calcPlotScaling() )
|
||||||
*
|
*
|
||||||
* \see calcPlotScaling(), calcTickSpacing()
|
* \see calcPlotScaling(), calcTickSpacing()
|
||||||
*/
|
*/
|
||||||
double scale;
|
double scale;
|
||||||
/** \brief <b>calculated property:</b> time axis offset (calculated by calcPlotScaling() )
|
/** \brief <b>calculated property:</b> axis offset (calculated by calcPlotScaling() )
|
||||||
*
|
*
|
||||||
* \see calcPlotScaling(), calcTickSpacing()
|
* \see calcPlotScaling(), calcTickSpacing()
|
||||||
*/
|
*/
|
||||||
@ -709,6 +749,12 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPCoordinateAxis: public QObject {
|
|||||||
/** \brief axis label of the axis */
|
/** \brief axis label of the axis */
|
||||||
QString axisLabel;
|
QString axisLabel;
|
||||||
|
|
||||||
|
/** \brief tick values are the actual x/y-coordiniate, divided by this value (e.g. pu \f$ \pi \f$ to have an axis with values <tt>0, pi, 2pi, 3pi ...</tt>) */
|
||||||
|
double tickUnitFactor;
|
||||||
|
|
||||||
|
/** \brief name of the factor tickUnitFactor. This string is used in tick-labels to write e.g. \c "2pi" instead of 6.28... */
|
||||||
|
QString tickUnitName;
|
||||||
|
|
||||||
|
|
||||||
/** \brief calculates the tick spacing for a linear axis that spans \a awidth and that should
|
/** \brief calculates the tick spacing for a linear axis that spans \a awidth and that should
|
||||||
* show at least \a JKQTPCoordinateAxisStyle::minTicks JKQTPCoordinateAxisStyle::ticks.
|
* show at least \a JKQTPCoordinateAxisStyle::minTicks JKQTPCoordinateAxisStyle::ticks.
|
||||||
|
@ -445,7 +445,7 @@ enum JKQTPCALabelType {
|
|||||||
JKQTPCALTscientific, /*!< \brief print the numbers in scientific notation, e.g. \c "1.23e-4" \image html axisstyle/JKQTPCALTscientific.png */
|
JKQTPCALTscientific, /*!< \brief print the numbers in scientific notation, e.g. \c "1.23e-4" \image html axisstyle/JKQTPCALTscientific.png */
|
||||||
JKQTPCALTexponentCharacter, /*!< \brief print the numbers and show a unit character, i.e. 5μ for \f$ 5\cdot 10^{-6} \f$ , \c 3k for \f$ 3\cdot 10^3 \f$ ... \image html axisstyle/JKQTPCALTexponentCharacter.png */
|
JKQTPCALTexponentCharacter, /*!< \brief print the numbers and show a unit character, i.e. 5μ for \f$ 5\cdot 10^{-6} \f$ , \c 3k for \f$ 3\cdot 10^3 \f$ ... \image html axisstyle/JKQTPCALTexponentCharacter.png */
|
||||||
JKQTPCALTexponent, /*!< \brief show numbers in exponential for, e.g. \f$ 3\cdot 10^5 \f$ ... \image html axisstyle/JKQTPCALTexponent.png */
|
JKQTPCALTexponent, /*!< \brief show numbers in exponential for, e.g. \f$ 3\cdot 10^5 \f$ ... \image html axisstyle/JKQTPCALTexponent.png */
|
||||||
JKQTPCALTprintf, /*!< \brief generate axis label from an arbitrary "printf" formatting string (see e.g. https://en.wikipedia.org/wiki/Printf_format_string ). The only data parameter is the tick value as \c double The following image shows an example for \c "y=%+.2f": \image html axisstyle/JKQTPCALTprintf.png */
|
JKQTPCALTprintf, /*!< \brief generate axis label from an arbitrary "printf" formatting string (see e.g. https://en.wikipedia.org/wiki/Printf_format_string ). The first data parameter is the tick value as \c double an the second is tickUnitName as string. The following image shows an example for \c "y=%+.2f": \image html axisstyle/JKQTPCALTprintf.png */
|
||||||
JKQTPCALTdate, /*!< \brief show numbers as dates \image html axisstyle/JKQTPCALTdate.png */
|
JKQTPCALTdate, /*!< \brief show numbers as dates \image html axisstyle/JKQTPCALTdate.png */
|
||||||
JKQTPCALTtime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTtime.png*/
|
JKQTPCALTtime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTtime.png*/
|
||||||
JKQTPCALTdatetime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTdatetime.png */
|
JKQTPCALTdatetime, /*!< \brief show numbers as times \image html axisstyle/JKQTPCALTdatetime.png */
|
||||||
@ -465,9 +465,9 @@ enum JKQTPCALabelType {
|
|||||||
/** \brief mode of the axis ticks
|
/** \brief mode of the axis ticks
|
||||||
* \ingroup jkqtpplottersupprt */
|
* \ingroup jkqtpplottersupprt */
|
||||||
enum JKQTPLabelTickMode {
|
enum JKQTPLabelTickMode {
|
||||||
JKQTPLTMLinOrPower=0, /*!< \brief linear, or log, depending on whether the axis is log */
|
JKQTPLTMLinOrPower=0, /*!< \brief linear, or log, depending on whether the axis is log \image html axisstyle/JKQTPLTMLinOrPower.png */
|
||||||
JKQTPLTMLin, /*!< \brief always linear (even for log-axes) */
|
JKQTPLTMLin, /*!< \brief always linear (even for log-axes) \image html axisstyle/JKQTPLTMLin.png */
|
||||||
JKQTPLTMPower, /*!< \brief powers (of the log-base) */
|
JKQTPLTMPower, /*!< \brief powers (of the log-base) \image html axisstyle/JKQTPLTMPower.png */
|
||||||
|
|
||||||
JKQTPLTMmax=JKQTPLTMPower
|
JKQTPLTMmax=JKQTPLTMPower
|
||||||
};
|
};
|
||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
@ -312,6 +312,62 @@ void doListAxisStyling(const QDir& outputDir, int iconsize, QColor backgroundCol
|
|||||||
plot.getXAxis()->setDrawMode1(JKQTPCADMLine|JKQTPCADMcompleteMinMaxArrow);
|
plot.getXAxis()->setDrawMode1(JKQTPCADMLine|JKQTPCADMcompleteMinMaxArrow);
|
||||||
imgheight=iconsize; plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,plot.getHeight()-imgheight,plot.getWidth(),imgheight).save(outputDir.absoluteFilePath("JKQTPCADMcompleteMinMaxArrow.png"), "png");
|
imgheight=iconsize; plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,plot.getHeight()-imgheight,plot.getWidth(),imgheight).save(outputDir.absoluteFilePath("JKQTPCADMcompleteMinMaxArrow.png"), "png");
|
||||||
|
|
||||||
|
|
||||||
|
plot.setXY(0.1,100,0.1,10);
|
||||||
|
plot.setWidgetSize(iconsize*4,4*iconsize);
|
||||||
|
plot.setShowKey(false);
|
||||||
|
plot.setGrid(true);
|
||||||
|
plot.getXAxis()->setLogAxis(true);
|
||||||
|
plot.getYAxis()->setLogAxis(false);
|
||||||
|
plot.getXAxis()->setShowZeroAxis(false);
|
||||||
|
plot.getYAxis()->setShowZeroAxis(false);
|
||||||
|
plot.getXAxis()->setDrawMode1(JKQTPCADMcomplete);
|
||||||
|
plot.getXAxis()->setDrawMode2(JKQTPCADMLine);
|
||||||
|
plot.getYAxis()->setDrawMode1(JKQTPCADMcomplete);
|
||||||
|
plot.getYAxis()->setDrawMode2(JKQTPCADMLine);
|
||||||
|
plot.getXAxis()->setAxisLabel("log. axis");
|
||||||
|
plot.getYAxis()->setAxisLabel("lin. axis");
|
||||||
|
|
||||||
|
plot.getXAxis()->setTickMode(JKQTPLTMLinOrPower);
|
||||||
|
plot.getYAxis()->setTickMode(JKQTPLTMLinOrPower);
|
||||||
|
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,plot.getWidth(),plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPLTMLinOrPower.png"), "png");
|
||||||
|
|
||||||
|
plot.getXAxis()->setTickMode(JKQTPLTMLin);
|
||||||
|
plot.getYAxis()->setTickMode(JKQTPLTMLin);
|
||||||
|
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,plot.getWidth(),plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPLTMLin.png"), "png");
|
||||||
|
|
||||||
|
plot.getXAxis()->setTickMode(JKQTPLTMPower);
|
||||||
|
plot.getYAxis()->setTickMode(JKQTPLTMPower);
|
||||||
|
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,plot.getWidth(),plot.getHeight()).save(outputDir.absoluteFilePath("JKQTPLTMPower.png"), "png");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
plot.setXY(0.1,10.0*JKQTPSTATISTICS_PI,0,2.1*JKQTPSTATISTICS_PI);
|
||||||
|
plot.setWidgetSize(iconsize*4,4*iconsize);
|
||||||
|
plot.setShowKey(false);
|
||||||
|
plot.setGrid(true);
|
||||||
|
plot.getXAxis()->setLogAxis(true);
|
||||||
|
plot.getYAxis()->setLogAxis(false);
|
||||||
|
plot.getXAxis()->setShowZeroAxis(false);
|
||||||
|
plot.getYAxis()->setShowZeroAxis(false);
|
||||||
|
plot.getXAxis()->setDrawMode1(JKQTPCADMcomplete);
|
||||||
|
plot.getXAxis()->setDrawMode2(JKQTPCADMLine);
|
||||||
|
plot.getYAxis()->setDrawMode1(JKQTPCADMcomplete);
|
||||||
|
plot.getYAxis()->setDrawMode2(JKQTPCADMLine);
|
||||||
|
plot.getXAxis()->setAxisLabel("log. axis");
|
||||||
|
plot.getYAxis()->setAxisLabel("lin. axis");
|
||||||
|
plot.getXAxis()->setMinTicks(5);
|
||||||
|
plot.getYAxis()->setMinTicks(3);
|
||||||
|
plot.getYAxis()->setTickLabelType(JKQTPCALTfrac);
|
||||||
|
|
||||||
|
plot.getXAxis()->setTickMode(JKQTPLTMLinOrPower);
|
||||||
|
plot.getYAxis()->setTickMode(JKQTPLTMLinOrPower);
|
||||||
|
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,plot.getWidth(),plot.getHeight()).save(outputDir.absoluteFilePath("axis_unit_scaling_none.png"), "png");
|
||||||
|
plot.getXAxis()->setTickUnitFactor(JKQTPSTATISTICS_PI);
|
||||||
|
plot.getXAxis()->setTickUnitName("\\;\\pi");
|
||||||
|
plot.getYAxis()->setTickUnitFactor(JKQTPSTATISTICS_PI);
|
||||||
|
plot.getYAxis()->setTickUnitName("\\;\\pi");
|
||||||
|
plot.grabPixelImage(QSize(plot.getWidth(),plot.getHeight()), false).copy(0,0,plot.getWidth(),plot.getHeight()).save(outputDir.absoluteFilePath("axis_unit_scaling_pi.png"), "png");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|