Esempio n. 1
0
/**
 * returns the spherical Bessel function of the second kind
 * needed for continuum states
 \param l = order of the function (orbital angular momentum)
 \param rho = independent variable (rho = k * r)
 */
double sphericalB::y(int l, double rho)
{
  switch (l)
    {
    case 0:
      return y0(rho);
    case 1:
      return y1(rho);
    case 2: 
      return y2(rho);
    case 3: 
      return y3(rho);
    case 4:
      return y4(rho);
    case 5:
      return y5(rho);
    case 6:
      return y6(rho);
    case 7:
      return y7(rho);
    default:
      cout << "no l>6 programed in sphericalB" << endl;
      return 0.;
    }
}
Esempio n. 2
0
void MathPlot::setupMultiAxisDemo(QCustomPlot *customPlot)
{
  customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);

  customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
  customPlot->legend->setVisible(true);
  QFont legendFont = font();  // start out with MainWindow's font..
  legendFont.setPointSize(9); // and make a bit smaller for legend
  customPlot->legend->setFont(legendFont);
  customPlot->legend->setBrush(QBrush(QColor(255,255,255,230)));
  // by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement:
  customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight);

  // setup for graph 0: key axis left, value axis bottom
  // will contain left maxwell-like function
  customPlot->addGraph(customPlot->yAxis, customPlot->xAxis);
  customPlot->graph(0)->setPen(QPen(QColor(255, 100, 0)));
  customPlot->graph(0)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // fill with texture of specified image
  customPlot->graph(0)->setLineStyle(QCPGraph::lsLine);
  customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
  customPlot->graph(0)->setName("Left maxwell function");

  // setup for graph 1: key axis bottom, value axis left (those are the default axes)
  // will contain bottom maxwell-like function
  customPlot->addGraph();
  customPlot->graph(1)->setPen(QPen(Qt::red));
  customPlot->graph(1)->setBrush(QBrush(QPixmap("://skin/images/balboa.jpg"))); // same fill as we used for graph 0
  customPlot->graph(1)->setLineStyle(QCPGraph::lsStepCenter);
  customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7));
  customPlot->graph(1)->setErrorType(QCPGraph::etValue);
  customPlot->graph(1)->setName("Bottom maxwell function");

  // setup for graph 2: key axis top, value axis right
  // will contain high frequency sine with low frequency beating:
  customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2);
  customPlot->graph(2)->setPen(QPen(Qt::blue));
  customPlot->graph(2)->setName("High frequency sine");

  // setup for graph 3: same axes as graph 2
  // will contain low frequency beating envelope of graph 2
  customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2);
  QPen blueDotPen;
  blueDotPen.setColor(QColor(30, 40, 255, 150));
  blueDotPen.setStyle(Qt::DotLine);
  blueDotPen.setWidthF(4);
  customPlot->graph(3)->setPen(blueDotPen);
  customPlot->graph(3)->setName("Sine envelope");

  // setup for graph 4: key axis right, value axis top
  // will contain parabolically distributed data points with some random perturbance
  customPlot->addGraph(customPlot->yAxis2, customPlot->xAxis2);
  customPlot->graph(4)->setPen(QColor(50, 50, 50, 255));
  customPlot->graph(4)->setLineStyle(QCPGraph::lsNone);
  customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4));
  customPlot->graph(4)->setName("Some random data around\na quadratic function");

  // generate data, just playing with numbers, not much to learn here:
  QVector<double> x0(25), y0(25);
  QVector<double> x1(15), y1(15), y1err(15);
  QVector<double> x2(250), y2(250);
  QVector<double> x3(250), y3(250);
  QVector<double> x4(250), y4(250);
  for (int i=0; i<25; ++i) // data for graph 0
  {
    x0[i] = 3*i/25.0;
    y0[i] = exp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]);
  }
  for (int i=0; i<15; ++i) // data for graph 1
  {
    x1[i] = 3*i/15.0;;
    y1[i] = exp(-x1[i]*x1[i])*(x1[i]*x1[i])*2.6;
    y1err[i] = y1[i]*0.25;
  }
  for (int i=0; i<250; ++i) // data for graphs 2, 3 and 4
  {
    x2[i] = i/250.0*3*M_PI;
    x3[i] = x2[i];
    x4[i] = i/250.0*100-50;
    y2[i] = sin(x2[i]*12)*cos(x2[i])*10;
    y3[i] = cos(x3[i])*10;
    y4[i] = 0.01*x4[i]*x4[i] + 1.5*(rand()/(double)RAND_MAX-0.5) + 1.5*M_PI;
  }

  // pass data points to graphs:
  customPlot->graph(0)->setData(x0, y0);
  customPlot->graph(1)->setDataValueError(x1, y1, y1err);
  customPlot->graph(2)->setData(x2, y2);
  customPlot->graph(3)->setData(x3, y3);
  customPlot->graph(4)->setData(x4, y4);
  // activate top and right axes, which are invisible by default:
  customPlot->xAxis2->setVisible(true);
  customPlot->yAxis2->setVisible(true);
  // set ranges appropriate to show data:
  customPlot->xAxis->setRange(0, 2.7);
  customPlot->yAxis->setRange(0, 2.6);
  customPlot->xAxis2->setRange(0, 3.0*M_PI);
  customPlot->yAxis2->setRange(-70, 35);
  // set pi ticks on top axis:
  QVector<double> piTicks;
  QVector<QString> piLabels;
  piTicks << 0  << 0.5*M_PI << M_PI << 1.5*M_PI << 2*M_PI << 2.5*M_PI << 3*M_PI;
  piLabels << "0" << QString::fromUtf8("½π") << QString::fromUtf8("π") << QString::fromUtf8("1½π") << QString::fromUtf8("2π") << QString::fromUtf8("2½π") << QString::fromUtf8("3π");
  customPlot->xAxis2->setAutoTicks(false);
  customPlot->xAxis2->setAutoTickLabels(false);
  customPlot->xAxis2->setTickVector(piTicks);
  customPlot->xAxis2->setTickVectorLabels(piLabels);
  // add title layout element:
  customPlot->plotLayout()->insertRow(0);
  customPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(customPlot, "Way too many graphs in one plot"));
  // set labels:
  customPlot->xAxis->setLabel("Bottom axis with outward ticks");
  customPlot->yAxis->setLabel("Left axis label");
  customPlot->xAxis2->setLabel("Top axis label");
  customPlot->yAxis2->setLabel("Right axis label");
  // make ticks on bottom axis go outward:
  customPlot->xAxis->setTickLength(0, 5);
  customPlot->xAxis->setSubTickLength(0, 3);
  // make ticks on right axis go inward and outward:
  customPlot->yAxis2->setTickLength(3, 3);
  customPlot->yAxis2->setSubTickLength(1, 1);
}
Esempio n. 3
0
void Highscore::addGraphOneBestToOneActual(QCustomPlot *plot, Run rL, Run rB) {

    plot->legend->setVisible(true);
    plot->legend->setFont(QFont("Helvetica",9));
    plot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));

    int typePointsCount = rB.typePoints.size();
    int xMin = -1;
    int xMax = typePointsCount+1;
    int yMin = 0;
    double yMax = 0;
    int yMaxErr = 0;

    QVector<double> x(typePointsCount), y(typePointsCount), y2(typePointsCount*11), x2(typePointsCount*11);
    for(int i = 0; i<typePointsCount; i++) {
        y[i] = 1/ (rB.typePoints.at(i).timeInMilliSeconds/60000.0);
        x[i] = i;
        yMax = std::max(y[i],yMax);
        for(double j = 0; j<11; j++) {
            y2[11*i+j] =  rB.typePoints.at(i).error;
            x2[11*i+j] =  (i-0.02)+(0.004*j)+0.04;
        }
        yMaxErr = std::max(rB.typePoints.at(i).error,yMaxErr);

    }
    plot->addGraph(plot->xAxis, plot->yAxis);
    plot->graph(0)->setName("Anschläge / Minute");
    plot->graph(0)->setData(x,y);
    plot->graph(0)->setLineStyle((QCPGraph::LineStyle)(1));
    plot->graph(0)->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1)));

    QPen graphPen;
    graphPen.setColor(QColor(200, 50, 0, 85));
    graphPen.setWidthF(2);
    plot->graph(0)->setPen(graphPen);

    plot->addGraph(plot->xAxis, plot->yAxis2);
    plot->graph(1)->setName("Fehler");
    plot->graph(1)->setData(x2,y2);
    plot->graph(1)->setLineStyle((QCPGraph::LineStyle)(5));

    QPen graphPen1;
    graphPen1.setColor(QColor(200, 50, 0, 100));
    graphPen1.setWidthF(3);
    plot->graph(1)->setPen(graphPen1);

    //plot->graph(0)->setBrush(QBrush(QColor(255,200,20,70)));

    typePointsCount = rL.typePoints.size();
    xMin = -1;
    xMax = typePointsCount+1;

    QVector<double> x3(typePointsCount), y3(typePointsCount), y4(typePointsCount*11), x4(typePointsCount*11);
    for(int i = 0; i<typePointsCount; i++) {
        y3[i] = 1/ (rL.typePoints.at(i).timeInMilliSeconds/60000.0);
        x3[i] = i;
        yMax = std::max(y3[i],yMax);
        for(double j = 0; j<11; j++) {
            y4[11*i+j] =  rL.typePoints.at(i).error;
            x4[11*i+j] =  (i-0.02)+(0.004*j)-0.04;
        }
        yMaxErr = std::max(rL.typePoints.at(i).error,yMaxErr);

    }
    plot->addGraph(plot->xAxis, plot->yAxis);
    plot->graph(2)->setName("Anschläge / Minute");
    plot->graph(2)->setData(x3,y3);
    plot->graph(2)->setLineStyle((QCPGraph::LineStyle)(1));
    plot->graph(2)->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1)));

    QPen graphPen2;
    graphPen2.setColor(QColor(130, 30, 0, 85));
    graphPen2.setWidthF(2);
    plot->graph(2)->setPen(graphPen2);

    plot->addGraph(plot->xAxis, plot->yAxis2);
    plot->graph(3)->setName("Fehler");
    plot->graph(3)->setData(x4,y4);
    plot->graph(3)->setLineStyle((QCPGraph::LineStyle)(5));

    QPen graphPen3;
    graphPen3.setColor(QColor(130, 30, 0, 100));
    graphPen3.setWidthF(3);
    plot->graph(3)->setPen(graphPen3);

    plot->yAxis2->setVisible(true);
    plot->xAxis2->setVisible(true);
    plot->xAxis->setVisible(true);

    plot->xAxis->setLabel("Durchlauf");
    plot->yAxis->setLabel("Anschläge pro Minute");
    plot->yAxis2->setLabel("Fehler");

    plot->xAxis->setRange(xMin, xMax);
    plot->yAxis->setRange(yMin, yMax+1);
    plot->yAxis2->setRange(yMin,yMaxErr*1.5 );
    plot->xAxis2->setRange(xMin, xMax);

    plot->xAxis->setAutoTickStep(false);
    plot->xAxis->setTickStep(1);
    plot->xAxis->setSubTickCount(1);


    plot->xAxis2->setTickLength(0, 0);
    plot->xAxis2->setSubTickLength(0, 0);
    plot->xAxis2->setTickStep(false);
    plot->xAxis2->setAutoTickLabels(false);
    plot->xAxis2->setTickLabels(false);

    plot->yAxis2->setAutoTickStep(false);
    plot->yAxis2->setTickStep(1);
    plot->yAxis2->setSubTickCount(0);
    plot->yAxis2->setTickLength(3, 3);
    plot->yAxis2->setSubTickLength(0, 0);


    //plot->graph(0)->setBrush(QBrush(QColor(255,200,20,70)));
}
Esempio n. 4
0
void Form::setupStyledDemo(QCustomPlot *customPlot)
{
  demoName = "Style Demo";

  // prepare data:
  QVector<double> x1(20), y1(20);
  QVector<double> x2(100), y2(100);
  QVector<double> x3(20), y3(20);
  QVector<double> x4(20), y4(20);

/*
  // add the text label at the top:
  QCPItemText *textLabel = new QCPItemText(customPlot);
  customPlot->addItem(textLabel);
  textLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
  textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
  textLabel->position->setCoords(0.5, 0); // place position at center/top of axis rect
  textLabel->setText("Text Item Demo");
  textLabel->setFont(QFont(font().family(), 16)); // make font a bit larger
  textLabel->setPen(QPen(Qt::black)); // show black border around text

  // add the arrow:
  QCPItemLine *arrow = new QCPItemLine(customPlot);
  customPlot->addItem(arrow);
  arrow->start->setParentAnchor(textLabel->bottom);
  arrow->end->setCoords(4, 1.6); // point to (4, 1.6) in x-y-plot coordinates
  arrow->setHead(QCPLineEnding::esSpikeArrow);
*/

  for (int i=0; i<x1.size(); ++i)
  {
    x1[i] = i/(double)x1.size()*10;
    y1[i] = qCos(x1[i]*0.8+qSin(x1[i]*0.16+1.0))*qSin(x1[i]*0.54)+1.4;
  }
  for (int i=0; i<x2.size(); ++i)
  {
    x2[i] = i/(double)x2.size()*10;
    y2[i] = qCos(x2[i]*0.85+qSin(x2[i]*0.165+1.1))*qSin(x2[i]*0.50)+1.7;
  }

  for (int i=0; i<x3.size(); ++i)
  {
    x3[i] = i/(double)x3.size()*10;
    y3[i] = 0.05+3*(0.5+qCos(x3[i]*x3[i]*0.2+2)*0.5)/(double)(x3[i]+0.7)+qrand()/(double)RAND_MAX*0.01;
  }

  // create and configure plottables:
  QCPGraph *graph1 = customPlot->addGraph();
  graph1->setData(x1, y1);
  graph1->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
  graph1->setPen(QPen(QColor(120, 120, 120), 2));

  QCPGraph *graph2 = customPlot->addGraph();
  graph2->setData(x2, y2);
  graph2->setPen(Qt::NoPen);
  graph2->setBrush(QColor(200, 200, 200, 20));
  //graph2->setChannelFillGraph(graph1);


  QCPBars *bars1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
  customPlot->addPlottable(bars1);
  bars1->setWidth(9/(double)x3.size());
  bars1->setData(x3, y3);
  bars1->setPen(Qt::NoPen);
  bars1->setBrush(QColor(10, 140, 70, 160));

  // set some pens, brushes and backgrounds:
  customPlot->xAxis->setBasePen(QPen(Qt::white, 1));
  customPlot->yAxis->setBasePen(QPen(Qt::white, 1));
  customPlot->xAxis->setTickPen(QPen(Qt::white, 1));
  customPlot->yAxis->setTickPen(QPen(Qt::white, 1));
  customPlot->xAxis->setSubTickPen(QPen(Qt::white, 1));
  customPlot->yAxis->setSubTickPen(QPen(Qt::white, 1));
  customPlot->xAxis->setTickLabelColor(Qt::white);
  customPlot->yAxis->setTickLabelColor(Qt::white);
  customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
  customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
  customPlot->xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
  customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
  customPlot->xAxis->grid()->setSubGridVisible(true);
  customPlot->yAxis->grid()->setSubGridVisible(true);
  customPlot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
  customPlot->yAxis->grid()->setZeroLinePen(Qt::NoPen);
  customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
  customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);

  QLinearGradient plotGradient;
  plotGradient.setStart(0, 0);
  plotGradient.setFinalStop(0, 350);
  plotGradient.setColorAt(0, QColor(80, 8, 80));
  plotGradient.setColorAt(1, QColor(50, 50, 50));
  customPlot->setBackground(plotGradient);
  QLinearGradient axisRectGradient;
  axisRectGradient.setStart(0, 0);
  axisRectGradient.setFinalStop(0, 350);
  axisRectGradient.setColorAt(0, QColor(80, 80, 80));
  axisRectGradient.setColorAt(1, QColor(30, 100, 0));
  customPlot->axisRect()->setBackground(axisRectGradient);

  customPlot->rescaleAxes();
  customPlot->yAxis->setRange(0, 2);
}