trase
Line Style

This is an example of using the Style class for a Line

example_line_style.svg
Output
#include "trase.hpp"
#include <fstream>
using namespace trase;
int main() {
// create figure and axis
auto fig = figure();
auto ax = fig->axis();
// create x and y vectors
const int n = 100;
std::vector<float> x(n);
std::vector<float> y(n);
const float k = 1.f;
auto logistic = [k](const float x) { return 1.f / (1.f + std::exp(-k * x)); };
for (int i = 0; i < n; ++i) {
x[i] = -6.f + 12.f * static_cast<float>(i) / n;
y[i] = logistic(x[i]);
}
// create a trase dataset and then plot it using a line geometry
auto data = create_data().x(x).y(y);
auto plt = ax->line(data);
// set line color = red and line width = 10
plt->style().color(RGBA(255, 0, 0)).line_width(10);
// label axis
ax->xlabel("x");
ax->ylabel("y");
// output to chosen backend
#ifdef TRASE_EXAMPLES_SVG_BACKEND
std::ofstream out;
out.open("example_line_style.svg");
BackendSVG backend(out);
fig->draw(backend);
out.close();
#endif
#ifdef TRASE_EXAMPLES_GL_BACKEND
BackendGL backend;
fig->show(backend);
#endif
}