QCutomPlot簡介
官網網址及介紹
QCustomPlot is a Qt C++ widget for plotting and data visualization. It has no further dependencies and is well documented. This plotting library focuses on making good looking, publication quality 2D plots, graphs and charts, as well as offering high performance for realtime visualization applications. Have a look at the Setting Up and the Basic Plotting tutorials to get started.
QCustomPlot can export to various formats such as vectorized PDF files and rasterized images like PNG, JPG and BMP. QCustomPlot is the solution for displaying of realtime data inside the application as well as producing high quality plots for other media.
其主要就是用來創建各種二維圖,而且能夠保存為很多文件格式。在QT下,是一個非常好用的畫圖庫。
畫圖基本步驟
基本步驟是根據官網Tutorials完成的。
1. 先下載需要的文檔。里面包含了編程所需的.h和.cpp文件以及例子等文檔。我選擇了最新的下載,畢竟最新的解決了已知bug。
2. 在QT中新建一個WidgetApplication。
3. 將下載下來的“qcustomplot.h”和“qcustomplot.cpp”這兩個文件添加到項目中
4. 非常重要的一點--要在.pro文件中添加“printsupport”。添加的位置在“QT += widgets”的后面
5. 在ui中添加一個widget控件,然后將其進行提升,提升為QCustomPlot
6. 在“mainwidget.h”中包含一下“qcustomplot.h”頭文件,這時就可以編譯運行了,如果不出意外,得到
至此,准備工作都已經完成,接下來就是在坐標系上畫圖了。
正式畫一個簡單的圖
先上效果圖
步驟
- 創建x軸和y軸所需要的數據
- 創建一個“畫布”
- 在畫布上將x軸和y軸對應的數據設置好
- 非必須,由於默認情況下x和y軸都是從“原點"(0,0)開始,所以為了顯示全部圖片,可以設置一下軸的范圍
- 將圖畫出