-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery_parallel_coordinates.cpp
More file actions
82 lines (74 loc) · 2.65 KB
/
gallery_parallel_coordinates.cpp
File metadata and controls
82 lines (74 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @file gallery_parallel_coordinates.cpp
* @brief Parallel Coordinates Plot with Multi-Dimensional Data
* @author plotly.cpp contributors
* @date 2025
*
* @example gallery_parallel_coordinates.cpp
*
* This gallery example demonstrates creating a parallel coordinates plot using
* Plotly.cpp. Parallel coordinates are effective for visualizing
* multi-dimensional data by representing each data point as a line connecting
* values across multiple parallel axes.
*
* Features demonstrated:
* - Multi-dimensional data visualization using parallel coordinates
* - Custom dimension configuration with ranges and constraints
* - Interactive brushing and filtering capabilities
* - Custom tick values and labels for categorical data
* - Constraint ranges for data filtering on specific dimensions
* - Color coding of parallel lines for pattern identification
*
* The plot displays four dimensions (A, B, C, D) with different configurations:
* - Dimension A: Numeric range with constraint filtering
* - Dimension B: Custom tick positions for specific value highlighting
* - Dimension C: Custom text labels replacing numeric values
* - Dimension D: Standard numeric range without constraints
*
* @image html parallel_coordinates.png "Multi-Dimensional Parallel Coordinates
* Plot"
*
*/
#include "plotly/plotly.hpp"
#include "utils/arg_parser.hpp"
#include <vector>
auto main(int argc, char *argv[]) -> int {
// Parse command line arguments
auto args = parseGalleryArgs(argc, argv);
// Create a plotly figure
plotly::Figure fig;
fig.openBrowser(args.headless);
// Create the parallel coordinates trace
plotly::Object trace = {
{"type", "parcoords"},
{"line", {{"color", "blue"}}},
{"dimensions",
{{{"range", {1, 5}},
{"constraintrange", {1, 2}},
{"label", "A"},
{"values", {1, 4}}},
{{"range", {1, 5}},
{"label", "B"},
{"values", {3, 1.5}},
{"tickvals", {1.5, 3, 4.5}}},
{{"range", {1, 5}},
{"label", "C"},
{"values", {2, 4}},
{"tickvals", {1, 2, 4, 5}},
{"ticktext", {"text 1", "text 2", "text 4", "text 5"}}},
{{"range", {1, 5}}, {"label", "D"}, {"values", {4, 2}}}}}};
// Create the plot
std::vector<plotly::Object> data = {trace};
fig.newPlot(data);
if (!args.headless) {
fig.waitClose();
} else {
// Save image instead of opening browser
plotly::Object imageOpts = {{"format", "png"},
{"width", 800},
{"height", 600},
{"filename", "parallel_coordinates"}};
fig.downloadImage(imageOpts);
}
return 0;
}