|
77 | 77 | //! - `savefig` : Save plot with given path |
78 | 78 |
|
79 | 79 | extern crate pyo3; |
80 | | -use self::pyo3::types::IntoPyDict; |
| 80 | +use self::pyo3::types::{IntoPyDict, PyDictMethods}; |
81 | 81 | use self::pyo3::{PyResult, Python}; |
82 | 82 | pub use self::Grid::{Off, On}; |
83 | 83 | use self::PlotOptions::{Domain, Images, Pairs, Path}; |
84 | 84 | use std::collections::HashMap; |
85 | 85 | use std::fmt::Display; |
| 86 | +use std::borrow::BorrowMut; |
| 87 | +use std::ffi::CString; |
86 | 88 |
|
87 | 89 | type Vector = Vec<f64>; |
88 | 90 |
|
@@ -463,7 +465,7 @@ impl Plot for Plot2D { |
463 | 465 | } |
464 | 466 |
|
465 | 467 | // Plot |
466 | | - Python::with_gil(|py| { |
| 468 | + Python::attach(|py| { |
467 | 469 | // Input data |
468 | 470 | let x = self.domain.clone(); |
469 | 471 | let ys = self.images.clone(); |
@@ -502,24 +504,24 @@ impl Plot for Plot2D { |
502 | 504 | let plot_type = self.plot_type.clone(); |
503 | 505 |
|
504 | 506 | // Global variables to plot |
505 | | - let globals = |
506 | | - vec![("plt", py.import_bound("matplotlib.pyplot")?)].into_py_dict_bound(py); |
507 | | - globals.as_gil_ref().set_item("x", x)?; |
508 | | - globals.as_gil_ref().set_item("y", ys)?; |
509 | | - globals.as_gil_ref().set_item("pair", pairs)?; |
510 | | - globals.as_gil_ref().set_item("n", y_length)?; |
511 | | - globals.as_gil_ref().set_item("p", pair_length)?; |
| 507 | + let mut globals = |
| 508 | + vec![("plt", py.import("matplotlib.pyplot")?)].into_py_dict(py)?; |
| 509 | + globals.borrow_mut().set_item("x", x)?; |
| 510 | + globals.borrow_mut().set_item("y", ys)?; |
| 511 | + globals.borrow_mut().set_item("pair", pairs)?; |
| 512 | + globals.borrow_mut().set_item("n", y_length)?; |
| 513 | + globals.borrow_mut().set_item("p", pair_length)?; |
512 | 514 | if let Some(fs) = fig_size { |
513 | | - globals.as_gil_ref().set_item("fs", fs)?; |
| 515 | + globals.borrow_mut().set_item("fs", fs)?; |
514 | 516 | } |
515 | | - globals.as_gil_ref().set_item("dp", dpi)?; |
516 | | - globals.as_gil_ref().set_item("gr", grid)?; |
517 | | - globals.as_gil_ref().set_item("pa", path)?; |
| 517 | + globals.borrow_mut().set_item("dp", dpi)?; |
| 518 | + globals.borrow_mut().set_item("gr", grid)?; |
| 519 | + globals.borrow_mut().set_item("pa", path)?; |
518 | 520 | if let Some(xl) = self.xlim { |
519 | | - globals.as_gil_ref().set_item("xl", xl)?; |
| 521 | + globals.borrow_mut().set_item("xl", xl)?; |
520 | 522 | } |
521 | 523 | if let Some(yl) = self.ylim { |
522 | | - globals.as_gil_ref().set_item("yl", yl)?; |
| 524 | + globals.borrow_mut().set_item("yl", yl)?; |
523 | 525 | } |
524 | 526 |
|
525 | 527 | // Plot Code |
@@ -702,7 +704,7 @@ impl Plot for Plot2D { |
702 | 704 | plot_string.push_str(&format!("plt.savefig(pa, dpi={})", dpi)[..]); |
703 | 705 | } |
704 | 706 |
|
705 | | - py.run_bound(&plot_string[..], Some(&globals), None)?; |
| 707 | + py.run(&CString::new(plot_string)?, Some(&globals), None)?; |
706 | 708 | Ok(()) |
707 | 709 | }) |
708 | 710 | } |
|
0 commit comments