1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-13 22:48:50 -05:00
implot/README.md

105 lines
6.0 KiB
Markdown
Raw Normal View History

2020-04-24 17:56:10 -04:00
# ImPlot
2020-05-03 01:37:48 -04:00
ImPlot is an immediate mode plotting widget for [Dear ImGui](https://github.com/ocornut/imgui). It aims to provide a first-class API that will make ImGui users feel right at home. ImPlot is well suited for visualizing program data in real-time 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-04-29 15:39:46 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/controls.gif" width="285"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/dnd.gif" width="285"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/log.gif" width="285">
2020-04-27 18:04:02 -04:00
2020-04-29 15:39:46 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/bar.gif" width="285"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/query.gif" width="285">
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/views.gif" width="285">
2020-04-29 15:27:23 -04:00
2020-05-31 17:37:04 -04:00
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/noise.gif" width="285"> <img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/stock.gif" width="285">
<img src="https://raw.githubusercontent.com/wiki/epezent/implot/screenshots/multiy.gif" width="285">
2020-04-25 10:02:51 -04:00
## Features
2020-04-24 17:56:10 -04:00
2020-05-03 01:46:20 -04:00
- multiple plot types:
- line
- scatter
- vertical/horizontal bars
- error bars
- pie charts
- 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)
- reversible and lockable axes
2020-05-11 02:10:57 -04:00
- support for 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.
- optional plot titles, axis labels, and grid labels
2020-04-26 18:37:57 -04:00
- optional legend with toggle buttons to quickly show/hide items
2020-04-26 18:13:22 -04:00
- size-aware grid with smart labels that are always power-of-ten multiples of 1, 2, and 5
- default styling based on current ImGui theme, but most elements can be customized independently
- mouse cursor location display and optional crosshairs cursor
- customizable data getters and data striding (just like ImGui:PlotLine)
2020-04-25 10:02:51 -04:00
- relatively good performance for high density plots
2020-05-29 14:04:16 -04:00
- support for single and double precision data
2020-04-24 17:56:10 -04:00
2020-04-25 10:02:51 -04:00
## Usage
2020-05-16 10:21:01 -04:00
The API is used just like any other ImGui `BeginX`/`EndX` pair. First, start a plotting context with `ImPlot::BeginPlot()`. Next, plot as many items as you want with the provided `PlotX` functions (e.g. `PlotLine()`, `PlotBars()`, `PlotErrorBars()`, 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
if (ImPlot::BeginPlot("My Plot")) {
2020-05-16 10:21:01 -04:00
ImPlot::PlotLine("My Line Plot", x_data, y_data, 1000);
ImPlot::PlotBars("My Bar Plot", values, 10);
2020-04-26 18:13:22 -04:00
...
ImPlot::EndPlot();
2020-04-25 10:02:51 -04:00
}
```
2020-04-26 18:37:57 -04:00
Consult `implot_demo.cpp` for a comprehensive example of ImPlot's features.
## Integration
2020-04-27 18:21:40 -04:00
Just add `implot.h`, `implot.cpp`, and optionally `implot_demo.cpp` to your sources. This assumes you already have an ImGui-ready environment. If not, 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
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
**Q: Is ImPlot suitable for real-time plotting?**
A: Yes, within reason. You can plot tens to hundreds of thousands of points without issue, but don't expect plotting over a million to be a buttery smooth experience. We do our best to keep it fast and avoid memory allocations.
**Q: Can plot styles be modified?**
2020-05-03 01:37:48 -04:00
A: Yes. Plot colors, palettes, and various styling variables can be pushed/popped or modified permanently on startup.
2020-04-28 02:53:38 -04:00
**Q: Does ImPlot support logarithmic scaling?**
A: Yep!
2020-05-11 02:10:57 -04:00
**Q: Does ImPlot support multiple y-axes? x-axes?**
A: Yes to y-axes (up to three), "not yet" to x-axes.
2020-05-01 09:50:08 -04:00
**Q: Does ImPlot support [insert plot type]?**
2020-04-28 02:53:38 -04:00
A: Maybe. Check the gallery and demo 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: 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 and matplotlib for these purposes.
2020-05-29 14:03:20 -04:00
**Q: Does ImPlot handle double precision data?**
A: Yes, ImPlot accepts both `float` and `double` for all of its plotting functions.
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
2020-04-28 22:42:33 -04:00
A: Yes, you can use the C binding, [cimplot](https://github.com/cimgui/cimplot) with most high level languages.
2020-04-29 15:41:39 -04:00
## Special Notes
- By default, no anti-aliasing is done on line plots for performance reasons. If you use 4x MSAA, then you likely won't even notice. However, you can re-enable AA with the `ImPlotFlags_AntiAliased` flag.
- If you plan to render several thousands lines or points, then you should consider enabling 32-bit indices by uncommenting `#define ImDrawIdx unsigned int` in your `imconfig.h` file, OR handling the `ImGuiBackendFlags_RendererHasVtxOffset` flag in your renderer (the official OpenGL3 renderer supports this). If you fail to do this, then you may at some point hit the maximum number of indices that can be rendered.