Closed Shrav108 closed 3 months ago
Hi,
Can you please show your Rust code and the python log file?
I've implemented the feature for the plot with dual Y and a single X (known as twin-x).
Basically, we can call the draw_with_twinx
function after calling the draw
function.
For example, see the code below (and the figure).
use plotpy::{Curve, Plot, StrError};
use std::f64::consts::PI;
fn main() -> Result<(), StrError> {
// data
let np = 201;
let mut x = vec![0.0; np];
let mut y1 = vec![0.0; np];
let mut y2 = vec![0.0; np];
let dx = 4.0 / (np as f64);
for i in 0..np {
x[i] = (i as f64) * dx;
y1[i] = f64::exp(x[i]);
y2[i] = f64::sin(2.0 * PI * x[i]);
}
// curve
let mut curve = Curve::new();
curve.set_line_color("red").draw(&x, &y1);
curve.set_line_color("blue").draw_with_twin_x(&y2);
// add curve to plot
let mut plot = Plot::new();
plot.add(&curve) // must occur before set twinx options
.grid_and_labels("time (s)", "exp function")
.set_label_x_color("green")
.set_label_y_color("red")
.set_label_y_twinx("sin function")
.set_label_y_twinx_color("blue");
// save figure
plot.save("/tmp/plotpy/doc_tests/doc_curve_twinx.svg")?;
Ok(())
}
Thank you for showing how it is done. I ran your code on windows. here is the log file results
Error:
Error: "python3 failed; please see the log file"
Log File :
Traceback (most recent call last): File "D:\Hydrostatic\hydrostatic\doc_curve_twinx.py", line 3, in
import numpy as np ModuleNotFoundError: No module named 'numpy'
Does this library work on windows ?
Hi,
I haven't tested it on Windows. But it seems that others have successfully (see this: https://github.com/cpmech/plotpy/issues/49).
I suppose that if you have python3 + numpy + scipy + matplotlib installed, everything should work.
Cheers
I am trying to plot some graph and want to include in egui interface. When I create a graph and try to save, I get this error
Error : python3 failed; please see the log file
What is the solution ?
Also, How to plot 2 curves/lines with the same x axis like given below ?