Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris00 committed Nov 3, 2024
1 parent c00f238 commit 6bf29c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ keywords = ["plot", "graph", "curve", "surface"]
categories = ["science", "visualization", "mathematics", "graphics"]

[dependencies]
numpy = "0.21"
ndarray = "0.15.6"
numpy = "0.22.1"
ndarray = "0.16.1"
curve-sampling = { version = "0.5", optional = true, git = "https://github.com/Chris00/rust-curve-sampling.git" }
lazy_static = "1.4.0"

[dependencies.pyo3]
version = "0.21.2"
version = "0.22.5"
features = ["auto-initialize"]

[features]
default = ["curve-sampling"]

[dev-dependencies]
doc-comment = "0.3.3"
polars-core = { version = "0.38.1", features = ["fmt"] }
polars-core = { version = "0.44.2", features = ["fmt"] }
11 changes: 7 additions & 4 deletions examples/flower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ use matplotlib as plt;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let (fig, [[mut ax]]) = plt::subplots()?;
let pseudacorus_sepal_length = Series::new("Pseudacorus_Sepal_Length",
let pseudacorus_sepal_length = Series::new(
"Pseudacorus_Sepal_Length".into(),
&[6.0,6.0,5.8,6.5,5.7,6.8,6.5,6.8,7.0,6.2,6.5,6.6,7.0,7.0,7.5,7.0,
6.8,6.5,6.3,6.2,6.9,6.3,6.3,7.0,6.2,6.8,6.2,6.3,5.8,5.9,6.2,6.3,
6.9,7.3,7.5,6.4,6.6,6.4,6.7,6.4,6.4,6.6,6.4,6.2,6.3,7.9,6.9,6.2,
5.9,6.3]);
let pseudacorus_sepal_width = Series::new("Pseudacorus_Sepal_width",
let pseudacorus_sepal_width = Series::new(
"Pseudacorus_Sepal_width".into(),
&[4.0,3.1,4.0,3.8,3.4,3.7,4.7,4.0,4.5,3.2,3.9,4.0,4.1,4.0,4.6,4.4,
4.0,4.2,3.9,4.0,4.8,4.0,4.2,3.8,3.6,3.3,3.4,3.5,3.1,3.7,4.4,4.5,
4.4,4.2,4.2,4.4,4.0,4.2,4.0,4.9,4.3,4.4,3.6,3.8,3.5,4.3,4.6,3.8,
3.6,3.8]);
let df = DataFrame::new(
vec![pseudacorus_sepal_length,pseudacorus_sepal_width])?;
let df = DataFrame::new(vec![
Column::Series(pseudacorus_sepal_length),
Column::Series(pseudacorus_sepal_width)])?;
println!("df is {:?}", &df);
let x_col = df.column("Pseudacorus_Sepal_Length")?.f64()?;
let y_col = df.column("Pseudacorus_Sepal_width")?.f64()?;
Expand Down
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ lazy_static! {

/// Container for most of the (sub-)plot elements: Axis, Tick,
/// [`Line2D`], Text, Polygon, etc., and sets the coordinate system.
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct Axes {
ax: PyObject,
}
Expand Down Expand Up @@ -190,28 +190,29 @@ impl Figure {
) -> Result<[[Axes; C]; R], Error> {
Python::with_gil(|py| {
let axs = self.fig
.call_method1(py, "subplots", (R, C))?;
.bind(py)
.call_method1("subplots", (R, C))?;
let axes;
if R == 1 {
if C == 1 {
axes = grid(|_,_| Axes { ax: axs.clone() });
axes = grid(|_,_| Axes { ax: axs.clone().unbind() });
} else { // C > 1
let axg: &Bound<PyArray1<PyObject>> =
axs.downcast_bound(py).unwrap();
axs.downcast().unwrap();
axes = grid(|_,c| {
let ax = axg.get_owned(c).unwrap();
Axes { ax } });
}
} else { // R > 1
if C == 1 {
let axg: &Bound<PyArray1<PyObject>> =
axs.downcast_bound(py).unwrap();
axs.downcast().unwrap();
axes = grid(|r,_| {
let ax = axg.get_owned(r).unwrap();
Axes { ax } });
} else { // C > 1
let axg: &Bound<PyArray2<PyObject>> =
axs.downcast_bound(py).unwrap();
axs.downcast().unwrap();
axes = grid(|r, c| {
let ax = axg.get_owned([r, c]).unwrap();
Axes { ax } });
Expand All @@ -238,8 +239,8 @@ impl Figure {
}

/// Save the figure to a file.
pub fn save(&self) -> Savefig {
Savefig { fig: self.fig.clone(), dpi: None }
pub fn save(&self) -> Savefig<'_> {
Savefig { fig: &self.fig, dpi: None }
}

/// Default width: 6.4, default height: 4.8
Expand All @@ -256,12 +257,12 @@ impl Figure {

/// Options for saving figures.
#[must_use]
pub struct Savefig {
fig: PyObject,
pub struct Savefig<'a> {
fig: &'a PyObject,
dpi: Option<f64>,
}

impl Savefig {
impl<'a> Savefig<'a> {
pub fn dpi(&mut self, dpi: f64) -> &mut Self {
if dpi > 0. {
self.dpi = Some(dpi);
Expand Down Expand Up @@ -632,7 +633,7 @@ impl<'a> PlotOptions<'a> {
}
}

fn kwargs(&'a self, py: Python<'a>) -> Bound<PyDict> {
fn kwargs(&'a self, py: Python<'a>) -> Bound<'a, PyDict> {
let kwargs = PyDict::new_bound(py);
if self.animated {
kwargs.set_item("animated", true).unwrap()
Expand Down

0 comments on commit 6bf29c2

Please sign in to comment.