improved log-axis-example
@ -29,7 +29,7 @@ All test-projects are Qt-projects that use qmake to build. You can load them int
|
|||||||
|
|
||||||
| Screenshot | Description | Notes |
|
| Screenshot | Description | Notes |
|
||||||
|:-------------:| ------------- | ------------- |
|
|:-------------:| ------------- | ------------- |
|
||||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | [logarithmic axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | `JKQTPxyLineGraph` and `JKQTPgeoText`<br/>C++ vector of data<br/>logarithmic axes<br/>plot line styles<br/>internal LaTeX parser<br/>add commenting text to a graph |
|
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | [logarithmic axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_logaxes) | `JKQTPxyLineGraph` and `JKQTPgeoText`<br/>C++ vector of data<br/>logarithmic axes and styling<br/>plot line styles<br/>internal LaTeX parser<br/>add commenting text to a graph |
|
||||||
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_dates_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_timeaxis_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | [date/time axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | `JKQTPxyLineGraph` and `JKQTPfilledVerticalRangeGraph`<br/>C++ vector of data<br/>date/time axes<br/>plot min/max range graph<br/>internal LaTeX parser<br/>data from CSV files |
|
| [![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_dates_small.png)<br>![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_dateaxes_timeaxis_small.png)](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | [date/time axes](https://github.com/jkriege2/JKQtPlotter/tree/master/test/jkqtplotter_simpletest_dateaxes) | `JKQTPxyLineGraph` and `JKQTPfilledVerticalRangeGraph`<br/>C++ vector of data<br/>date/time axes<br/>plot min/max range graph<br/>internal LaTeX parser<br/>data from CSV files |
|
||||||
|
|
||||||
|
|
||||||
|
@ -3263,7 +3263,7 @@ void JKQTmathText::useXITS()
|
|||||||
#ifdef AUTOLOAD_XITS_FONTS
|
#ifdef AUTOLOAD_XITS_FONTS
|
||||||
//qDebug()<<"has XITS: "<<fdb.families().contains("XITS");
|
//qDebug()<<"has XITS: "<<fdb.families().contains("XITS");
|
||||||
if (!fdb.families().contains("XITS")) {
|
if (!fdb.families().contains("XITS")) {
|
||||||
int i;
|
int i=0;
|
||||||
if (QFile::exists(":/JKQTmathText/fonts/xits-bold.otf")) { i=QFontDatabase::addApplicationFont(":/JKQTmathText/fonts/xits-bold.otf"); }
|
if (QFile::exists(":/JKQTmathText/fonts/xits-bold.otf")) { i=QFontDatabase::addApplicationFont(":/JKQTmathText/fonts/xits-bold.otf"); }
|
||||||
//qDebug()<<QFontDatabase::applicationFontFamilies(i);
|
//qDebug()<<QFontDatabase::applicationFontFamilies(i);
|
||||||
if (QFile::exists(":/JKQTmathText/fonts/xits-bolditalic.otf")) { i=QFontDatabase::addApplicationFont(":/JKQTmathText/fonts/xits-bolditalic.otf"); }
|
if (QFile::exists(":/JKQTmathText/fonts/xits-bolditalic.otf")) { i=QFontDatabase::addApplicationFont(":/JKQTmathText/fonts/xits-bolditalic.otf"); }
|
||||||
@ -3285,6 +3285,8 @@ void JKQTmathText::useXITS()
|
|||||||
//bool hasXITSMath=false;
|
//bool hasXITSMath=false;
|
||||||
QString XITSMathfam;
|
QString XITSMathfam;
|
||||||
for (int i=0; i<fdb.families().size(); i++) {
|
for (int i=0; i<fdb.families().size(); i++) {
|
||||||
|
//::cout<<fdb.families().at(i).simplified().toStdString()<<"\n";
|
||||||
|
//qDebug()<<fdb.families().at(i).simplified();
|
||||||
if (fdb.families().at(i).contains("XITS Math")) {
|
if (fdb.families().at(i).contains("XITS Math")) {
|
||||||
//hasXITSMath=true;
|
//hasXITSMath=true;
|
||||||
XITSMathfam=fdb.families().at(i);
|
XITSMathfam=fdb.families().at(i);
|
||||||
|
@ -152,7 +152,9 @@ bool JKQTPgeoText::getYMinMax(double& miny, double& maxy, double& smallestGreate
|
|||||||
|
|
||||||
void JKQTPgeoText::draw(JKQTPEnhancedPainter& painter) {
|
void JKQTPgeoText::draw(JKQTPEnhancedPainter& painter) {
|
||||||
painter.save();
|
painter.save();
|
||||||
|
#ifdef USE_XITS_FONTS
|
||||||
|
parent->get_mathText()->useXITS();
|
||||||
|
#endif
|
||||||
parent->get_mathText()->set_fontSize(fontSize*parent->get_fontSizeMultiplier());
|
parent->get_mathText()->set_fontSize(fontSize*parent->get_fontSizeMultiplier());
|
||||||
parent->get_mathText()->set_fontColor(color);
|
parent->get_mathText()->set_fontColor(color);
|
||||||
parent->get_mathText()->parse(text);
|
parent->get_mathText()->parse(text);
|
||||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 5.9 KiB |
BIN
screenshots/jkqtplotter_simpletest_logaxes_lowqmathrendering.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
screenshots/jkqtplotter_simpletest_logaxes_nominorgrid.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
screenshots/logaxis_set_labelType.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
screenshots/logaxis_set_minorticks.png
Normal file
After Width: | Height: | Size: 22 KiB |
@ -41,29 +41,70 @@ Then a `JKQTPgeoText` is added to the graph, which shows the function plotted in
|
|||||||
```c++
|
```c++
|
||||||
// 4. Also we add a text-element in the plot to show the plotted function
|
// 4. Also we add a text-element in the plot to show the plotted function
|
||||||
// This element (JKQTPgeoText) is taken from the set of geometric elements
|
// This element (JKQTPgeoText) is taken from the set of geometric elements
|
||||||
// and is simply parametrized by a position (1.8/10) and the text to display.
|
// and is simply parametrized by a position (1.25/10) and the text to display.
|
||||||
// In addition you can also set the font size (here to 15)
|
// In addition you can also set the font size (here to 15)
|
||||||
plot.addGraph(new JKQTPgeoText(&plot, 1.8, 10, "\\frac{A}{A_{stat}}=\\frac{1}{\\sqrt{\\left(1-\\eta^2\\right)^2+\\left(2{\\eta}D\\right)^2}}", 15));
|
// Use '$...$' around the actual math string to ensure rendering with a math font
|
||||||
// for nicer rendering we set the fonts used by the internal LaTeX parser instance to XITS
|
// (the internal renderer uses XITS fonts by default, which are free and auto-distributed
|
||||||
plot.get_plotter()->get_mathText()->useXITS();
|
// and loaded in the library). If you don't use the math-mode modifiers, the default
|
||||||
|
// font of the other rendering text is used, which might not be suitable for
|
||||||
|
// high-quality math rendering.
|
||||||
|
plot.addGraph(new JKQTPgeoText(&plot, 1.25, 10, "$\\frac{A}{A_{stat}}=\\frac{1}{\\sqrt{\\left(1-\\eta^2\\right)^2+\\left(2{\\eta}D\\right)^2}}$", 15));
|
||||||
```
|
```
|
||||||
|
The difference between not using and using `$...$` for the equation can be seen below (left: no $-math-mode, right: using $-math-mode):
|
||||||
|
![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_lowqmathrendering.png) ![](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_highqmathrendering.png)
|
||||||
|
|
||||||
Finally the y-axis is switched to logarithmic scaling and the axis labels are set:
|
Finally the y-axis is switched to logarithmic scaling and the axis labels are set:
|
||||||
```c++
|
```c++
|
||||||
// 4. set y-axis to logarithmic (x-axis would be analogous)
|
// 5. set y-axis to logarithmic (x-axis would be analogous, but using `plot.get_xAxis()`)
|
||||||
// and set axis labels (using LaTeX notation)
|
|
||||||
plot.get_yAxis()->set_logAxis(true);
|
plot.get_yAxis()->set_logAxis(true);
|
||||||
plot.get_yAxis()->set_axisLabel("Amplitude A/A_{stat}");
|
// now we set the number of label ticks to 9 (you give the count if minor between two majors,
|
||||||
plot.get_xAxis()->set_axisLabel("relative driving frequency \\eta=\\omega/\\omega_0");
|
// so if you want ticks for 1,2,3,...,10,20,30,...,100... you need to use 9:
|
||||||
|
plot.get_yAxis()->set_minorTicks(9);
|
||||||
|
// the minor grid is not shown by default. You can switch it on:
|
||||||
|
plot.get_yAxis()->set_drawMinorGrid(true);
|
||||||
|
// usually axis ticks are shown as numbers 0.01, 0.1, 1, 10, ... You can also force the scientific
|
||||||
|
// power-of-10 notation, using:
|
||||||
|
plot.get_yAxis()->set_labelType(JKQTPCALTexponent);
|
||||||
|
// the number of digits in JKQTPCALTexponent determines which labels are drawn in standard-notation,
|
||||||
|
// as compared to power-notation (e.g. if set to 1, the labels 0.1=10^{-1}, 1, 10 are shown in
|
||||||
|
// standard notation, the rest in power-notation. This tweak improves readability)
|
||||||
|
plot.get_yAxis()->set_labelDigits(0);
|
||||||
|
// minor tick labels are usually not displayed, but you can switch them on, using
|
||||||
|
//plot.get_yAxis()->set_minorTickLabelsEnabled(true);
|
||||||
|
// the axis font sizes can be set with:
|
||||||
|
plot.get_yAxis()->set_tickLabelFontSize(10); // axis tick labels
|
||||||
|
plot.get_yAxis()->set_minorTickLabelFontSize(7); // minor axis tick labels
|
||||||
|
plot.get_yAxis()->set_labelFontSize(14); // axis label size
|
||||||
|
plot.get_xAxis()->set_tickLabelFontSize(10); // axis tick labels
|
||||||
|
plot.get_xAxis()->set_minorTickLabelFontSize(7); // minor axis tick labels
|
||||||
|
plot.get_xAxis()->set_labelFontSize(14); // axis label size
|
||||||
|
// ... and finally set axis labels (using LaTeX notation and $...$ to improve rendering)
|
||||||
|
plot.get_yAxis()->set_axisLabel("Amplitude $A/A_{stat}$");
|
||||||
|
plot.get_xAxis()->set_axisLabel("relative driving frequency $\\eta=\\omega/\\omega_0$");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
As an alternative `JKQTPCALTexponentCharacter` does not use the power-of-10 notation, but uses the usual unit-characters, e.g. 0.001=1m, 0.000001=1µ, 10000=10k, ...
|
||||||
|
|
||||||
The result looks like this:
|
The result looks like this:
|
||||||
|
|
||||||
![jkqtplotter_simpletest_symbols_and_styles](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes.png)
|
![jkqtplotter_simpletest_logaxes](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes.png)
|
||||||
|
|
||||||
Without the logarithmic scaling we would have:
|
Without the logarithmic scaling we would have:
|
||||||
|
|
||||||
![jkqtplotter_simpletest_symbols_and_styles](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_nolog.png)
|
![jkqtplotter_simpletest_logaxes_nolog](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_nolog.png)
|
||||||
|
|
||||||
|
Switching the minor grid off results in a plot like this:
|
||||||
|
|
||||||
|
![jkqtplotter_simpletest_logaxes_nominorgrid](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtplotter_simpletest_logaxes_nominorgrid.png)
|
||||||
|
|
||||||
|
These examples show the results for different typical values for `set_minorTicks()`:
|
||||||
|
![logaxis_set_minorticks](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/logaxis_set_minorticks.png)
|
||||||
|
|
||||||
|
These examples show the results for different typical values for `set_labelType()`:
|
||||||
|
![logaxis_set_labelType](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/logaxis_set_labelType.png)
|
||||||
|
|
||||||
|
These examples show the results for different typical values for `set_labelType()`:
|
||||||
|
![logaxis_set_labelType](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/logaxis_set_labelType.png)
|
||||||
|
|
||||||
|
|
||||||
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
[Back to JKQTPlotter main page](https://github.com/jkriege2/JKQtPlotter/)
|
@ -49,7 +49,7 @@ int main(int argc, char* argv[])
|
|||||||
graph->set_lineWidth(1.5);
|
graph->set_lineWidth(1.5);
|
||||||
|
|
||||||
// graph title is made from symbol+penstyle
|
// graph title is made from symbol+penstyle
|
||||||
graph->set_title(QString("D=\\delta/\\omega_0=%1").arg(D[id]));
|
graph->set_title(QString("$D=\\delta/\\omega_0=%1$").arg(D[id]));
|
||||||
|
|
||||||
// add the graph to the plot, so it is actually displayed
|
// add the graph to the plot, so it is actually displayed
|
||||||
plot.addGraph(graph);
|
plot.addGraph(graph);
|
||||||
@ -59,23 +59,47 @@ int main(int argc, char* argv[])
|
|||||||
// This element (JKQTPgeoText) is taken from the set of geometric elements
|
// This element (JKQTPgeoText) is taken from the set of geometric elements
|
||||||
// and is simply parametrized by a position (1.25/10) and the text to display.
|
// and is simply parametrized by a position (1.25/10) and the text to display.
|
||||||
// In addition you can also set the font size (here to 15)
|
// In addition you can also set the font size (here to 15)
|
||||||
plot.addGraph(new JKQTPgeoText(&plot, 1.25, 10, "\\frac{A}{A_{stat}}=\\frac{1}{\\sqrt{\\left(1-\\eta^2\\right)^2+\\left(2{\\eta}D\\right)^2}}", 15));
|
// Use '$...$' around the actual math string to ensure rendering with a math font
|
||||||
// for nicer rendering we set the fonts used by the internal LaTeX parser instance to XITS
|
// (the internal renderer uses XITS fonts by default, which are free and auto-distributed
|
||||||
//plot.get_plotter()->get_mathText()->useXITS();
|
// and loaded in the library). If you don't use the math-mode modifiers, the default
|
||||||
|
// font of the other rendering text is used, which might not be suitable for
|
||||||
|
// high-quality math rendering.
|
||||||
|
plot.addGraph(new JKQTPgeoText(&plot, 1.25, 10, "$\\frac{A}{A_{stat}}=\\frac{1}{\\sqrt{\\left(1-\\eta^2\\right)^2+\\left(2{\\eta}D\\right)^2}}$", 15));
|
||||||
|
|
||||||
// 4. set y-axis to logarithmic (x-axis would be analogous)
|
// 5. set y-axis to logarithmic (x-axis would be analogous, but using `plot.get_xAxis()`)
|
||||||
// and set axis labels (using LaTeX notation)
|
|
||||||
plot.get_yAxis()->set_logAxis(true);
|
plot.get_yAxis()->set_logAxis(true);
|
||||||
plot.get_yAxis()->set_axisLabel("Amplitude A/A_{stat}");
|
// now we set the number of label ticks to 9 (you give the count if minor between two majors,
|
||||||
plot.get_xAxis()->set_axisLabel("relative driving frequency \\eta=\\omega/\\omega_0");
|
// so if you want ticks for 1,2,3,...,10,20,30,...,100... you need to use 9:
|
||||||
|
plot.get_yAxis()->set_minorTicks(9);
|
||||||
|
// the minor grid is not shown by default. You can switch it on:
|
||||||
|
plot.get_yAxis()->set_drawMinorGrid(true);
|
||||||
|
// usually axis ticks are shown as numbers 0.01, 0.1, 1, 10, ... You can also force the scientific
|
||||||
|
// power-of-10 notation, using:
|
||||||
|
plot.get_yAxis()->set_labelType(JKQTPCALTexponent);
|
||||||
|
// the number of digits in JKQTPCALTexponent determines which labels are drawn in standard-notation,
|
||||||
|
// as compared to power-notation (e.g. if set to 1, the labels 0.1=10^{-1}, 1, 10 are shown in
|
||||||
|
// standard notation, the rest in power-notation. This tweak improves readability)
|
||||||
|
plot.get_yAxis()->set_labelDigits(0);
|
||||||
|
// minor tick labels are usually not displayed, but you can switch them on, using
|
||||||
|
//plot.get_yAxis()->set_minorTickLabelsEnabled(true);
|
||||||
|
// the axis font sizes can be set with:
|
||||||
|
plot.get_yAxis()->set_tickLabelFontSize(10); // axis tick labels
|
||||||
|
plot.get_yAxis()->set_minorTickLabelFontSize(7); // minor axis tick labels
|
||||||
|
plot.get_yAxis()->set_labelFontSize(14); // axis label size
|
||||||
|
plot.get_xAxis()->set_tickLabelFontSize(10); // axis tick labels
|
||||||
|
plot.get_xAxis()->set_minorTickLabelFontSize(7); // minor axis tick labels
|
||||||
|
plot.get_xAxis()->set_labelFontSize(14); // axis label size
|
||||||
|
// ... and finally set axis labels (using LaTeX notation and $...$ to improve rendering)
|
||||||
|
plot.get_yAxis()->set_axisLabel("Amplitude $A/A_{stat}$");
|
||||||
|
plot.get_xAxis()->set_axisLabel("relative driving frequency $\\eta=\\omega/\\omega_0$");
|
||||||
|
|
||||||
|
|
||||||
// 5. autoscale the plot so the graph is contained
|
// 6. autoscale the plot so the graph is contained
|
||||||
plot.zoomToFit();
|
plot.zoomToFit();
|
||||||
|
|
||||||
// 6. show plotter and make it a decent size
|
// 7. show plotter and make it a decent size
|
||||||
plot.show();
|
plot.show();
|
||||||
plot.resize(600,400);
|
plot.resize(700,500);
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|