1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00
implot/README.md

167 lines
11 KiB
Markdown
Raw Normal View History

2020-04-24 17:56:10 -04:00
# ImPlot
2020-12-04 01:25:45 -05:00
ImPlot is an immediate mode, GPU accelerated plotting library for [Dear ImGui](https://github.com/ocornut/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.
2020-04-24 17:56:10 -04:00
2020-09-06 21:32:27 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/controls.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/dnd.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/pie.gif" width="270">
2020-04-27 18:04:02 -04:00
2020-09-06 20:42:08 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/query.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/bars.gif" width="270">
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/rt.gif" width="270">
2020-04-29 15:27:23 -04:00
2020-09-06 20:42:08 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/stem.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/markers.gif" width="270">
2020-09-06 20:43:55 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/shaded.gif" width="270">
2020-09-06 20:17:39 -04:00
2020-09-06 21:40:20 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/candle.gif" width="270"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/heat.gif" width="270">
2020-09-06 20:42:08 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/tables.gif" width="270">
2020-05-31 17:37:04 -04:00
2020-04-25 10:02:51 -04:00
## Features
2020-04-24 17:56:10 -04:00
2020-09-06 18:24:16 -04:00
- GPU accelerated rendering
2020-08-16 16:38:51 -04:00
- multiple plot types:
2020-06-08 22:00:04 -04:00
- line plots
2020-06-14 09:49:56 -04:00
- shaded plots
2020-06-08 22:00:04 -04:00
- scatter plots
- vertical/horizontal bars graphs
2020-06-08 21:59:20 -04:00
- vertical/horizontal error bars
2020-09-02 12:01:25 -04:00
- stem plots
2020-11-16 10:58:16 -05:00
- stair plots
2020-05-03 01:46:20 -04:00
- pie charts
2020-06-08 22:00:04 -04:00
- heatmap charts
2021-03-20 01:14:17 -04:00
- 1D/2D histograms
2020-09-17 21:42:28 -04:00
- images
2020-06-02 23:30:25 -04:00
- and more likely to come
2020-04-25 10:02:51 -04:00
- mix/match multiple plot items on a single plot
2020-04-26 18:37:57 -04:00
- configurable axes ranges and scaling (linear/log)
- subplots
2020-12-04 01:25:45 -05:00
- time formatted x-axes (US formatted or ISO 8601)
2020-04-26 18:37:57 -04:00
- reversible and lockable axes
2020-09-09 01:04:28 -04:00
- up to three independent y-axes
2020-04-26 18:37:57 -04:00
- controls for zooming, panning, box selection, and auto-fitting data
2020-04-28 21:28:03 -04:00
- controls for creating persistent query ranges (see demo)
2020-04-25 10:02:51 -04:00
- several plot styling options: 10 marker types, adjustable marker sizes, line weights, outline colors, fill colors, etc.
2021-03-20 01:17:34 -04:00
- 16 built-in colormaps and support for and user-added colormaps
2020-04-25 10:02:51 -04:00
- optional plot titles, axis labels, and grid labels
2020-12-04 01:25:45 -05:00
- optional and configurable legends with toggle buttons to quickly show/hide plot items
2021-03-20 01:17:34 -04:00
- default styling based on current ImGui theme, or completely custom plot styles
- customizable data getters and data striding (just like ImGui:PlotLine)
2020-09-09 01:04:28 -04:00
- accepts data as float, double, and 8, 16, 32, and 64-bit signed/unsigned integral types
2021-01-15 03:17:00 -05:00
- and more! (see Announcements [2020](https://github.com/epezent/implot/issues/48)/[2021](https://github.com/epezent/implot/issues/168))
2020-04-24 17:56:10 -04:00
2020-04-25 10:02:51 -04:00
## Usage
2020-12-04 01:25:45 -05:00
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!
2020-04-26 18:13:22 -04:00
2020-04-25 10:02:51 -04:00
```cpp
2020-10-23 17:27:45 -04:00
int bar_data[11] = ...;
float x_data[1000] = ...;
float y_data[1000] = ...;
2020-10-20 17:57:11 -04:00
ImGui::Begin("My Window");
if (ImPlot::BeginPlot("My Plot")) {
2020-10-20 17:57:11 -04:00
ImPlot::PlotBars("My Bar Plot", bar_data, 11);
2020-05-16 10:21:01 -04:00
ImPlot::PlotLine("My Line Plot", x_data, y_data, 1000);
2020-04-26 18:13:22 -04:00
...
ImPlot::EndPlot();
2020-04-25 10:02:51 -04:00
}
2020-10-20 17:57:11 -04:00
ImGui::End();
2020-04-25 10:02:51 -04:00
```
2020-10-20 17:57:11 -04:00
![Usage](https://raw.githubusercontent.com/wiki/epezent/implot/screenshots3/example.PNG)
2021-03-27 03:27:57 -04:00
Of course, there's much more you can do with ImPlot...
2020-04-26 18:37:57 -04:00
2021-03-27 03:27:57 -04:00
## Demos
A comprehensive example of ImPlot's features can be found in `implot_demo.h`. Add this file to your sources and call `ImPlot::ShowDemoWindow()` somewhere in your update loop. You are encouraged to use this file as a reference when needing to implement various plot types. The demo is always updated to show new plot types and features as they are added, so check back with each release!
2020-09-06 18:24:16 -04:00
An online version of the demo is hosted [here](https://traineq.org/implot_demo/src/implot_demo.html). 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](https://github.com/pthom) for creating and hosting this!
2021-03-27 03:27:57 -04:00
More sophisticated demos requiring lengthier code and/or third-party libraries can be found in a separate repository: [implot_demos](https://github.com/epezent/implot_demos). Here, you will find advanced signal processing and ImPlot usage in action. Please read the `Contributing` section of that repository if you have an idea for a new demo!
2020-04-26 18:37:57 -04:00
## Integration
2020-12-04 01:25:45 -05:00
0) Set up an [ImGui](https://github.com/ocornut/imgui) environment if you don't already have one.
1) Add `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](https://github.com/microsoft/vcpkg/tree/master/ports/implot).
2020-08-16 16:43:41 -04:00
2) Create and destroy an `ImPlotContext` wherever you do so for your `ImGuiContext`:
2020-08-16 16:38:51 -04:00
```cpp
ImGui::CreateContext();
ImPlot::CreateContext();
...
ImPlot::DestroyContext();
ImGui::DestroyContext();
```
2020-12-04 01:25:45 -05:00
You should be good to go!
2020-09-09 01:04:28 -04:00
If you want to test ImPlot quickly, consider trying [mahi-gui](https://github.com/mahilab/mahi-gui), which bundles ImGui, ImPlot, and several other packages for you.
2020-04-26 18:13:22 -04:00
2021-06-02 11:06:31 -04:00
## Extremely Important Note
2020-06-07 14:45:01 -04:00
Dear ImGui uses **16-bit indexing by default**, so high-density ImPlot widgets like `ImPlot::PlotHeatmap()` may produce too many vertices into `ImDrawList`, which causes an assertion failure and will result in data truncation and/or visual glitches. Therefore, it is **HIGHLY** recommended that you EITHER:
2021-06-02 11:06:31 -04:00
- **Option 1:** Enable 32-bit indices by uncommenting `#define ImDrawIdx unsigned int` in your ImGui [`imconfig.h`](https://github.com/ocornut/imgui/blob/master/imconfig.h#L89) file.
- **Option 2:** Handle the `ImGuiBackendFlags_RendererHasVtxOffset` flag in your renderer if you must use 16-bit indices. Many of the default ImGui rendering backends already support `ImGuiBackendFlags_RendererHasVtxOffset`. Refer to [this issue](https://github.com/ocornut/imgui/issues/2591) for more information.
2020-07-25 09:11:43 -04:00
2020-04-28 02:53:38 -04:00
## FAQ
**Q: Why?**
2020-05-03 01:37:48 -04:00
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.
2020-04-28 02:53:38 -04:00
2020-09-06 18:24:16 -04:00
**Q: Is ImPlot the right plotting library for me?**
2020-09-09 01:04:28 -04:00
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.
2020-09-06 18:24:16 -04:00
2020-12-04 01:25:45 -05:00
**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.
2020-09-01 22:03:48 -04:00
**Q: Is ImPlot suitable for plotting large datasets?**
2020-04-28 02:53:38 -04:00
2020-12-04 01:25:45 -05:00
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.
2020-04-28 02:53:38 -04:00
2020-12-09 20:44:08 -05:00
**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).
2020-04-28 02:53:38 -04:00
**Q: Can plot styles be modified?**
2020-12-04 01:25:45 -05:00
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.
2020-04-28 02:53:38 -04:00
2020-09-06 18:24:16 -04:00
**Q: Does ImPlot support logarithmic scaling or time formatting?**
2020-04-28 02:53:38 -04:00
2020-09-06 18:24:16 -04:00
A: Yep! Both logscale and timescale are supported.
2020-04-28 02:53:38 -04:00
2020-05-11 02:10:57 -04:00
**Q: Does ImPlot support multiple y-axes? x-axes?**
2020-12-04 01:25:45 -05:00
A: Yes. Up to three y-axes can be enabled. Multiple x-axes are not supported.
2020-05-11 02:10:57 -04:00
2020-05-01 09:50:08 -04:00
**Q: Does ImPlot support [insert plot type]?**
2020-04-28 02:53:38 -04:00
2021-01-15 03:17:00 -05:00
A: Maybe. Check the demo, gallery, or Announcements ([2020](https://github.com/epezent/implot/issues/48)/[2021](https://github.com/epezent/implot/issues/168))to see if your desired plot type is shown. If not, consider submitting an issue or better yet, a PR!
2020-04-28 02:53:38 -04:00
**Q: Does ImPlot support 3D plots?**
A: No, and likely never will since ImGui only deals in 2D rendering.
2020-06-07 14:45:01 -04:00
**Q: My plot lines look like crap!**
2021-06-02 11:06:31 -04:00
A: By default, no anti-aliasing is done on line plots for performance gains. If you use at least 4x MSAA, then you likely won't even notice. However, you can enable software AA per-plot with the `ImPlotFlags_AntiAliased` flag, or globally with `ImPlot::GetStyle().AntiAliasedLines = true;`.
2020-06-07 14:45:01 -04:00
2020-04-28 02:53:38 -04:00
**Q: Does ImPlot provide analytic tools?**
2020-08-16 16:38:51 -04:00
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.
2020-04-28 02:53:38 -04:00
**Q: Can plots be exported/saved to image?**
2020-09-06 18:29:28 -04:00
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.
2020-04-28 02:53:38 -04:00
2021-06-02 11:06:31 -04:00
**Q: Can a compile ImPlot as a dynamic library?**
A: Like ImGui, it is recommended that you compile and link ImPlot as a *static* library or directly as a part of your sources. However, if you are compiling ImPlot and ImGui as separate DLLs, make sure you set the current *ImGui* context with `ImPlot::SetImGuiContext(ImGuiContext* ctx)`. This ensures that global ImGui variables are correctly shared across the DLL boundary.
2020-04-29 09:13:23 -04:00
**Q: Can ImPlot be used with other languages/bindings?**
2020-04-28 22:43:01 -04:00
A: Yes, you can use the generated C binding, [cimplot](https://github.com/cimgui/cimplot) with most high level languages. [DearPyGui](https://github.com/hoffstadt/DearPyGui) provides a Python wrapper, among other things. [imgui-java](https://github.com/SpaiR/imgui-java) provides bindings for Java. A Rust binding, [implot-rs](https://github.com/4bb4/implot-rs), is currently in the works. An example using Emscripten can be found [here](https://github.com/pthom/implot_demo).