Qcustomplot how to resize graph?

Asked

Viewed 66 times

3

I’m trying to do a repeat histogram of 255 events, I don’t know what is the maximum amount of times this event can occur!

I have a array of 255 elements, already with the amount of repetitions of events and I want to show this in the graph using the QCustomPlot, but the size it is 4.8, 4.8, and my histogram hits 23079 or more, maybe much more.

How to Increase This 4.8, 4.8 and leave the chart far away?

Follows part of the code:

int grayScale[255] = {0};

//faco meus bang pra montar o array
QVector<double> x(255),y(255);
ui->customPlot->addGraph();
for(int i = 0; i < 255; i++)
{
    x[i] = i;
    y[i] = grayScale[i];
}
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setLabel("Tom");
ui->customPlot->yAxis->setLabel("Quantidade");
ui->customPlot->replot();

I await and thank you in advance!

1 answer

2


Normally the graph scale should be determined automatically so that all values are visible. Apparently, in your case, this isn’t happening.

You can force a scale using the method setRange(int x, int y). In your case you can try:

int grayScale[255] = {0};

//faco meus bang pra montar o array
QVector<double> x(255),y(255);
ui->customPlot->addGraph();
for(int i = 0; i < 255; i++)
{
    x[i] = i;
    y[i] = grayScale[i];
}
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setLabel("Tom");
ui->customPlot->yAxis->setLabel("Quantidade");

ui->customPlot->xAxis->setRange(0, 255); 
ui->customPlot->yAxis->setRange(0, 23079); // aqui deves alterar para o valor máximo no teu universo, por exemplo, guardando o valor numa variável `ui->customPlot->yAxis->setRange(0, maxGrayScale);` 

ui->customPlot->replot();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.