ImPlot is an immediate mode, GPU accelerated plotting library for Dear ImGui. It aims to provide a first-class API that ImGui fans will love. ImPlot is well suited for visualizing program data in real-time or creating interactive plots, and requires minimal code to integrate. Just like ImGui, it does not burden the end user with GUI state management, avoids STL containers and C++ headers, and has no external dependencies except for ImGui itself.
The API is used just like any other ImGui BeginX
/EndX
pair. First, start a new plot with ImPlot::BeginPlot()
. Next, plot as many items as you want with the provided PlotX
functions (e.g. PlotLine()
, PlotBars()
, PlotScatter()
, etc). Finally, wrap things up with a call to ImPlot::EndPlot()
. That's it!
int bar_data[11] = ...;
float x_data[1000] = ...;
float y_data[1000] = ...;
ImGui::Begin("My Window");
if (ImPlot::BeginPlot("My Plot")) {
ImPlot::PlotBars("My Bar Plot", bar_data, 11);
ImPlot::PlotLine("My Line Plot", x_data, y_data, 1000);
...
ImPlot::EndPlot();
}
ImGui::End();
Of course, there's much more you can do with ImPlot. Consult implot_demo.cpp
for a comprehensive example of ImPlot's features.
An online version of the demo is hosted here. You can view the plots and the source code that generated them. Note that this demo may not always be up to date and is not as performant as a desktop implementation, but it should give you a general taste of what's possible with ImPlot. Special thanks to pthom for creating and hosting this!
implot.h
, implot_internal.h
, implot.cpp
, implot_items.cpp
and optionally implot_demo.cpp
to your sources. Alternatively, you can get ImPlot using vcpkg.ImPlotContext
wherever you do so for your ImGuiContext
:ImGui::CreateContext();
ImPlot::CreateContext();
...
ImPlot::DestroyContext();
ImGui::DestroyContext();
You should be good to go!
If you want to test ImPlot quickly, consider trying mahi-gui, which bundles ImGui, ImPlot, and several other packages for you.
ImGuiBackendFlags_RendererHasVtxOffset
flag in your renderer when using 16-bit indices (the official OpenGL3 renderer supports this) and use an ImGui version with patch imgui@f6120f8, OR...#define ImDrawIdx unsigned int
in your ImGui imconfig.h
file.ImPlotFlags_AntiAliased
flag, or globally with ImPlot::GetStyle().AntiAliasedLines = true;
.ImPlot::SetImGuiContext(ImGuiContext* ctx)
. This ensures that global ImGui variables are correctly shared across the DLL boundary.Q: Why?
A: ImGui is an incredibly powerful tool for rapid prototyping and development, but provides only limited mechanisms for data visualization. Two dimensional plots are ubiquitous and useful to almost any application. Being able to visualize your data in real-time will give you insight and better understanding of your application.
Q: Is ImPlot the right plotting library for me?
A: If you're looking to generate publication quality plots and/or export plots to a file, ImPlot is NOT the library for you. ImPlot is geared toward plotting application data at realtime speeds. ImPlot does its best to create pretty plots (indeed, there are quite a few styling options available), but it will always favor function over form.
Q: Where is the documentation?
A: The API is thoroughly commented in implot.h
, and the demo in implot_demo.cpp
should be more than enough to get you started.
Q: Is ImPlot suitable for plotting large datasets?
A: Yes, within reason. You can plot tens to hundreds of thousands of points without issue, but don't expect millions to be a buttery smooth experience. That said, you can always downsample extremely large datasets by telling ImPlot to stride your data at larger intervals if needed.
Q: What data types can I plot?
A: ImPlot plotting functions accept most scalar types:
float
, double
, int8
, uint8
, int16
, uint16
, int32
, uint32
, int64
, uint64
. Arrays of custom structs or classes (e.g. Vector2f
or similar) are easily passed to ImPlot functions using the built in striding features (see implot.h
for documentation).
Q: Can plot styles be modified?
A: Yes. Data colormaps and various styling colors and variables can be pushed/popped or modified permanently on startup. Three default styles are available, as well as an automatic style that attempts to match you ImGui style.
Q: Does ImPlot support logarithmic scaling or time formatting?
A: Yep! Both logscale and timescale are supported.
Q: Does ImPlot support multiple y-axes? x-axes?
A: Yes. Up to three y-axes can be enabled. Multiple x-axes are not supported.
Q: Does ImPlot support [insert plot type]?
A: Maybe. Check the demo, gallery, or Announcements (2020/2021)to see if your desired plot type is shown. If not, consider submitting an issue or better yet, a PR!
Q: Does ImPlot support 3D plots?
A: No, and likely never will since ImGui only deals in 2D rendering.
Q: My plot lines look like crap!
A: See the note about anti-aliasing under Special Notes above.
Q: Does ImPlot provide analytic tools?
A: Not exactly, but it does give you the ability to query plot sub-ranges, with which you can process your data however you like.
Q: Can plots be exported/saved to image?
A: Not currently. Use your OS's screen capturing mechanisms if you need to capture a plot. ImPlot is not suitable for rendering publication quality plots; it is only intended to be used as a visualization tool. Post-process your data with MATLAB or matplotlib for these purposes.
Q: Can ImPlot be used with other languages/bindings?
A: Yes, you can use the generated C binding, cimplot with most high level languages. DearPyGui provides a Python wrapper, among other things. A Rust binding, implot-rs, is currently in the works. An example using Emscripten can be found here.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。