void matrixofpixels::HistogramPlotProperty(double Xmin, double Xmax, double Ymax) { changeitems(); setAxisAutoScale(this->xTop); setAxisAutoScale(this->xBottom); //setAxisFont(QwtPlot::xBottom,QFont("Helvetica",15,1)); QwtText xlabel("Value"); QwtText ylabel("Events"); QColor col(Qt::red); xlabel.setColor(col); ylabel.setColor(col); xlabel.setFont(QFont("Helvetica",15,1)); ylabel.setFont(QFont("Helvetica",15,1)); setAxisTitle(QwtPlot::xBottom,xlabel); setAxisTitle(QwtPlot::yLeft,ylabel); setCanvasBackground(QColor(Qt::white)); setAxisScale(QwtPlot::xBottom, Xmin, Xmax); setAxisMaxMinor(QwtPlot::xBottom, 0); setAxisScale(QwtPlot::yLeft, 0, Ymax); setAxisMaxMinor(QwtPlot::yLeft, 0); plotLayout()->setAlignCanvasToScales(true); his->attach(this); /*QwtPlotGrid **/grid = new QwtPlotGrid; grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); grid->attach(this); replot(); }
/** * Write data onto the screen as some graph * @return Returns the number of bytes written * @param buf Pointer to the buffer to write out. */ size_t PlpotSink::write(Buffer *buf) { if (pls == NULL || settings == NULL) { return 0; } float* src = (float*) buf->getData(); float ppeak = -1e9, npeak = 1e9; size_t len = settings->fft_ssb_points; // len = buf->getLength() / (sizeof(float)); float xscale; std::string xlabel("FFT point"); std::string ylabel("Logarithmic Spectral Power"); xscale = 1e-6 * settings->samplingfreq / float(settings->fft_points); xlabel = std::string("Video BW in MHz"); for (size_t i=0; i<len; i++) { xdata[i] = xscale*PLFLT(i); // ydata[i] = log10(abs(*(src+0))); // Re, skip Im if data is {Re,Im} // src += 2; if (*src == 0.0f) { ydata[i] = 1; } else { ydata[i] = log10(abs(*(src+0))); } src++; if (i > 16) { if (ydata[i] > ppeak) ppeak = ydata[i]; if (ydata[i] < npeak) npeak = ydata[i]; } } #if 0 std::cerr << "len=" << len << " npeak=" << npeak << " ppeak=" << ppeak << std::endl << std::flush; #endif pls->col0(2); pls->schr(0,0.5); pls->vpor(0.1, 0.9, 0.1, 0.9); pls->wind(xdata[0], xdata[len-1], npeak, ppeak); pls->clear(); pls->box("bcnst", 0.0, 0, "bnstv", 0.0, 0); pls->line(len, xdata, ydata); pls->lab(xlabel.c_str(), ylabel.c_str(), this->title.c_str()); return buf->getLength(); }
void CalcIncoherentScattering(const long long int iter_num, const double energy_MeV, SharedCompoundPtr target) { // Gen X axis int graduation=50; double radStep=180.0/(double)graduation; std::vector<double> rad; double sum=0.0; for(int i=0; i<graduation; i++) { rad.push_back(sum); sum+=radStep; } // Gen Y axis UniformRandomGenerator0to1 random(12345); std::vector<double> hist(graduation, 0); for(long long int i=0; i<iter_num; i++) { RunLight(i,iter_num); PointVector_t ray(1.0, 1.0, 1.0); SharedPhotonPtr photon = Photon::CreatePhoton(energy_MeV, ray); while(photon->IncoherentScattering(target, random) == MC_REJECTED) {} for(int j=0; j<graduation; j++) { if(photon->GetIncline_rad() < (double)(j *radStep)*M_PI/180.0 ) { hist[j]++; break; } } } double sumhist =std::accumulate(hist.begin(), hist.end(), 0.0); for(int i=0; i<hist.size(); i++) { hist[i] /=sumhist; } // Plot std::cout << "\r" << " "; std::string mark("*"); std::string xlabel("degree"); std::string ylabel("probability"); Plotter plotter(graduation, 18, xlabel, ylabel); plotter.Plot(rad, hist, mark); }