plotlib
plotlib copied to clipboard
Making ContinuousView struct field public
Hello,
In one of my projects using plotlib, (can be seen here), I'm overlaying several scatter plots in different colors into the same plot. In order of accomplish that, I'm using a pattern like the one below, which allows for an arbitrary number of individual scatter plots to be added to a single view. However, due to the borrow checker, and being unable to modify the ContinuousView
struct field representations
directly since it's not public, I've had to clone the library locally, modify it, and point my Cargo.toml
file there instead.
Would it be possible to open up those fields publicly? I realize it's typical to leave them private by default, but I'm not sure if there's a soundness or security implication that would get in the way. Alternatively, is there a more idiomatic way of doing this?
let mut scatter_plots: Vec<Plot> = Vec::new();
for i in 0..clusters.len() {
let mut rng = rand::thread_rng();
let color = format!("#{}", rng.gen_range(0, 999999).to_string()); // This is just a convenient way of coming up with different colors
let s: Plot = Plot::new(
vec![clusters[i].clone()] // clusters is of type Vec<Vec<(f64,f64)>>
)
.point_style(PointStyle::new().colour(color));
scatter_plots.push(c);
}
let mut v = ContinuousView::new()
.x_range(-5., 5.)
.y_range(-5., 5.)
.x_label("x-axis")
.y_label("y-axis");
for plot in scatter_plots {
v.representations.push(Box::new(plot.clone())); // Can't do this because the `representations` field is currently private.
// It compiles and works when I open that field publicly, though.
// v.add(plot.clone()); // Can't do this because Copy can't be implement on ContinuousView because of a String dependency, so the borrow checker doesn't like it
// I haven't found a way around this, since it seems to be based on language-level guarantees
}