Comments (6)
My guess is if we return an SVG and wrap it in a HTML file, that would work?
from plotters.
:dep plotters = { git = "https://github.com/38/plotters", default_features = false, features = ["evcxr"] }
extern crate plotters;
use plotters::prelude::*;
let figure = evcxr_figure((640, 480), |root| {
root.fill(&White);
let mut chart = ChartBuilder::on(&root)
.caption("y=x^2", &("Arial", 50).into_font())
.margin(5)
.x_label_area_size(30)
.y_label_area_size(30)
.build_ranged(-1f32..1f32, -0.1f32..1f32)?;
chart.configure_mesh().draw()?;
chart.draw_series(LineSeries::new(
(-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
&Red,
)).unwrap()
.label("y = x^2")
.legend(|(x,y)| Path::new(vec![(x,y), (x + 20,y)], &Red));
chart.configure_series_labels()
.background_style(&White.mix(0.8))
.border_style(&Black)
.draw()?;
Ok(())
});
figure
You should be able to use this.
from plotters.
@zacps Also, would you please give me some instructions on how to use evcxr with Jupyter.
I just tried the page, it shows compile errors even with the sample on that page.
from plotters.
Could you paste the error?
What jupyter and rust toolchain version you're using would also be helpful.
from plotters.
use std::fmt::Debug;
pub struct Matrix<T> {pub values: Vec<T>, pub row_size: usize}
impl<T: Debug> Matrix<T> {
pub fn evcxr_display(&self) {
let mut html = String::new();
html.push_str("<table>");
for r in 0..(self.values.len() / self.row_size) {
html.push_str("<tr>");
for c in 0..self.row_size {
html.push_str("<td>");
html.push_str(&format!("{:?}", self.values[r * self.row_size + c]));
html.push_str("</td>");
}
html.push_str("</tr>");
}
html.push_str("</table>");
println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", html);
}
}
let m = Matrix {values: vec![1,2,3,4,5,6,7,8,9], row_size: 3};
m
Compilation failed, but no parsable errors were found. STDERR:
Compiling user_code_1 v1.0.0 (/tmp/.tmpndVY1C/user_code_1)
error[E0308]: mismatched types
--> src/lib.rs:21:60
|
21 | evcxr_variable_store.put_variable::<String>(stringify!(m), m);
| ^ expected struct `std::string::String`, found struct `user_code_0::Matrix`
|
= note: expected type `std::string::String`
found type `user_code_0::Matrix<{integer}>`
error[E0277]: the trait bound `user_code_0::Matrix<{integer}>: std::marker::Copy` is not satisfied
--> src/lib.rs:22:22
|
22 | evcxr_variable_store.assert_copy_type(m);
| ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `user_code_0::Matrix<{integer}>`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: Could not compile `user_code_1`.
To learn more, run the command again with --verbose.
STDOUT:
The Rust version is
$ rustc --version
rustc 1.37.0-nightly (37d001e4d 2019-05-29)
from plotters.
I can reproduce, it seems to be broken on nightly.
Works for me on stable (rustup default stable
).
from plotters.
Related Issues (20)
- [BUG] Even your own Examples doesn't work HOT 3
- [BUG] Drawing series can hang under certain conditions HOT 7
- [BUG] Can't outline/stroke polygon for svg HOT 1
- [BUG] example crash under centos 7.5 HOT 1
- [BUG] plotters-canvas build error
- plotters v0.3.5 has RUSTSEC-2023-0020 from font-kit v0.11.0 HOT 2
- [BUG] titled function draw text position error when generating PNG file HOT 3
- [BUG] unsafe preconditions violated HOT 12
- default font size?
- [BUG] Spacing between words removed HOT 1
- Step charts
- [BUG] 'static lifetime requirement for `ChartContext`
- pie RGBAcolor
- Warning due to use of deprecated default_features HOT 1
- [BUG] AsRangedCoord not implemented for Range<NaiveDateTime>
- Drawing 3d Voxels
- [BUG] Time for axes does not work on single day with different hours
- [Feature Request] Stroke width/outline for text in bitmap backend
- [Feature Request] stacked plots
- [Feature Request] Text bounding box
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotters.