ScatterPlot¶
Overview¶
-
class omdi::ScatterPlot : public omdi::Plot, public omdi::plots::DataPlot<omdi::Points>¶
Class for creating 2D scatter plots.
The
omdi::ScatterPlotclass draws collections of scattered 2D points (e.g.omdi::Points) using ImPlot. It supports:plotting one or more named point datasets,
an option to enforce equal aspect ratio for X and Y axes,
per-series visual customization via
ImPlotSpec,reuse of the common
omdi::Plotinterface.
Datasets are stored by value inside the inherited
omdi::plots::DataPlot<omdi::Points>base, so no external data lifetime management is required.
Usage example¶
Basic usage with two point sets:
// Create scatter plot with just a label — no data yet
auto scatter = omdi::ScatterPlot { "Scatter Example" };
// Add or replace all datasets at once
scatter.update_all({
{ "set A", omdi::Points { {0.0f, 1.0f, 2.0f}, {1.0f, 0.5f, 0.25f}, 3 } },
{ "set B", omdi::Points { xs_vec, ys_vec, n } }
});
// Or construct with initial data directly:
auto scatter2 = omdi::ScatterPlot { "Scatter Example", {
{ "set A", omdi::Points { xs_vec, ys_vec, n } }
}};
// Inside your ImGui/ImPlot drawing code:
scatter.plot();
Data members¶
-
bool omdi::ScatterPlot::m_aspect_equal¶
Flag controlling whether the plot uses an equal aspect ratio.
When
true, the X and Y axes are scaled so that one unit in X matches one unit in Y, which is useful for geometric or spatial data. Whenfalse, the aspect ratio is free.
Constructor¶
-
omdi::ScatterPlot::ScatterPlot(const std::string &label = "ScatterPlot", const std::map<std::string, omdi::Points> &data = {}, bool aspect_equal = true)¶
Construct a scatter plot with an optional label and initial datasets.
- Parameters:
label – Plot label / title (used in ImPlot). Defaults to
"ScatterPlot".data – Map from dataset names to
omdi::Pointsvalues. Data is copied into the plot on construction. Defaults to an empty map.aspect_equal – Whether to enforce equal aspect ratio for the axes (defaults to
true).
Inherited from DataPlot<Points>¶
The following methods are inherited from
omdi::plots::DataPlot<omdi::Points> and can be called directly
on a omdi::ScatterPlot instance.
-
void omdi::ScatterPlot::update(const std::string &label, omdi::Points data)¶
Replace or insert a single named point dataset.
- Parameters:
label – Name of the dataset to update.
data – New
omdi::Pointsvalue (copied by value).
-
void omdi::ScatterPlot::update_all(std::map<std::string, omdi::Points> new_data)¶
Replace all datasets at once.
- Parameters:
new_data – Map of new datasets. Replaces the entire contents of the internal data store.
-
auto omdi::ScatterPlot::set_spec(const std::string &label, const ImPlotSpec &spec) -> void¶
Set the per-series plot specification for a named dataset.
- Parameters:
label – Dataset label to associate the spec with.
spec –
ImPlotSpeccontrolling the visual appearance of the series.
-
auto omdi::ScatterPlot::get_spec(const std::string &label) const -> ImPlotSpec¶
Get the per-series plot specification for a named dataset.
- Parameters:
label – Dataset label whose spec to retrieve.
- Returns:
The
ImPlotSpecassociated withlabel.
Plotting¶
-
void omdi::ScatterPlot::plot() override¶
Render the scatter plot.
This method overrides
omdi::Plot::plot()and:iterates over the entries in the internal data map,
for each dataset, retrieves the X/Y arrays and point count from the corresponding
omdi::Points,applies the per-series
ImPlotSpec(retrieved viaomdi::ScatterPlot::get_spec()) to control visual style,draws the points using ImPlot’s scatter/marker primitives,
applies equal aspect ratio if
omdi::ScatterPlot::m_aspect_equalistrue.
It is typically called inside an ImGui/ImPlot plotting context.
Notes¶
omdi::ScatterPlotowns all dataset copies; no externalomdi::Pointsinstances need to remain alive.Enabling equal aspect ratio is recommended for spatial data where Euclidean distances and angles should not be visually distorted.
Use
omdi::ScatterPlot::update()to refresh a single series andomdi::ScatterPlot::update_all()to replace all series at once, for example when integrating with a simulation or background thread.