#[cfg(feature = "visualization")]
pub mod direct_plot;
#[cfg(feature = "visualization")]
pub mod plotters_ext;
use crate::error::Result;
use crate::vis::config::{OutputFormat, PlotConfig, PlotType};
use crate::DataFrame;
use crate::Series;
use std::path::Path;
#[allow(deprecated)]
#[deprecated(since = "0.1.0", note = "Use `pandrs::vis::text::plot_xy` instead")]
pub use crate::vis::text::plot_xy;
impl<T> Series<T>
where
T: Clone + Copy + Into<f32> + std::fmt::Debug,
{
#[allow(deprecated)]
#[deprecated(
since = "0.1.0",
note = "Use `Series.plot_to()` or `Series.line_plot()` instead"
)]
pub fn plot<P: AsRef<Path>>(&self, path: P, config: PlotConfig) -> Result<()> {
let values: Vec<f32> = self.values().iter().map(|v| (*v).into()).collect();
let indices: Vec<f32> = (0..values.len()).map(|i| i as f32).collect();
plot_xy(&indices, &values, path, config)
}
}
impl DataFrame {
#[allow(deprecated)]
#[deprecated(since = "0.1.0", note = "Use `DataFrame.scatter_xy()` instead")]
pub fn plot_xy<P: AsRef<Path>>(
&self,
x_col: &str,
y_col: &str,
path: P,
config: PlotConfig,
) -> Result<()> {
#[allow(deprecated)]
{
let x_values = self.get_column_numeric_values(x_col)?;
let y_values = self.get_column_numeric_values(y_col)?;
let x_f32: Vec<f32> = x_values.iter().map(|&v| v as f32).collect();
let y_f32: Vec<f32> = y_values.iter().map(|&v| v as f32).collect();
plot_xy(&x_f32, &y_f32, path, config)
}
}
#[allow(deprecated)]
#[deprecated(since = "0.1.0", note = "Use `DataFrame.multi_line_plot()` instead")]
pub fn plot_lines<P: AsRef<Path>>(
&self,
columns: &[&str],
path: P,
config: PlotConfig,
) -> Result<()> {
#[allow(deprecated)]
{
if let Some(&first_col) = columns.first() {
let values = self.get_column_numeric_values(first_col)?;
let values_f32: Vec<f32> = values.iter().map(|&v| v as f32).collect();
let indices: Vec<f32> = (0..self.row_count()).map(|i| i as f32).collect();
let mut custom_config = config;
custom_config.title = format!("{} ({})", custom_config.title, first_col);
return plot_xy(&indices, &values_f32, path, custom_config);
}
}
Err(crate::error::PandRSError::Empty(
"No columns to plot".to_string(),
))
}
}