Skip to content
No description, website, or topics provided.
C++ QMake
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Images
MyPlot.pro
README.md
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
myplot.cpp
myplot.h

README.md

My Plot

My Plot is a simple and lightweight Qt widget for plotting. It has no further dependencies on external libaries and can be easily integrated in Qt projects.

Contents

Setting Up

To get My Plot to work with your Qt application download the latest version of My Plot and copy the myplot.cpp and myplot.h file to your application directory. In Qt Creator right click on the root entry of your project in the left sidebar and choose Add Existing Files...:

In the dialog, select the myplot.cpp and myplot.h file, to add them to your project. Your project structure and .pro file should look something like this:

Next, place a QWidget on your form, right click on it and click Promote to...

In the dialog, enter MyPlot in the Promoted Class Name input field. The input next to Header File should be filled automatically with myplot.h, then click "Add" to add Mylot to the promoted classes list and finally click Promote to turn the QWidget on your form into a MyPlot.

You won't see any immediate visual changes in Qt Creater, but while running the application, you will see an empty plot with axes. We recommend to rename the widgets objectName to, e.g., plot. You might also change the centralWidget layout to vertical or horizontal.

Plotting

If you have promoted a widget in QtCreator, you'll access the respective widget via ui->plot, or whatever name you gave the widget.

To make any kind of changes to the plot appear on screen, call ui->plot->replot(). Note that replot is automatically called when the widget is resized.

// Generate some data
QVector<double> X, Y;
for (int i = -10; i <= 10; i++)
{
	X.append(i);
	Y.append(0.25*i*i-5);
}

// Plot the data
ui->plot->plotXY(X, Y);
// Set axes labels
ui->plot->setXLabel("X");
ui->plot->setYLabel("Y");
// Set axes ranges
ui->plot->setAxes(-10, 10, -10, 10);

ui->plot->replot();

A detailed example is available with the My Plot project in this repository.

You can’t perform that action at this time.