Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (3)
Update git ignore
· e6c960de
Rui Vieira
authored
Mar 31, 2019
e6c960de
Add support for line segments
· cedeec04
Rui Vieira
authored
Apr 17, 2019
cedeec04
Update README.md. Release 0.1.7
· 3f71197d
Rui Vieira
authored
Apr 17, 2019
3f71197d
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
3f71197d
...
...
@@ -3,3 +3,4 @@
**/*.rs.bk
.idea
*.iml
Cargo.lock
CHANGELOG.md
View file @
3f71197d
# changelog
*
0.1.7
*
Add line segments
*
0.1.6
*
Add vertical and horizontal lines
...
...
Cargo.toml
View file @
3f71197d
[package]
name
=
"matplotrust"
version
=
"0.1.
6
"
version
=
"0.1.
7
"
authors
=
[
"Rui Vieira <ruidevieira@googlemail.com>"
]
exclude
=
[
"examples/figures/**/*"
,
".idea/**/*"
,
"binder/**/*"
]
description
=
"A simple wrap around Python's matplotlib."
...
...
README.md
View file @
3f71197d
...
...
@@ -22,6 +22,7 @@ Python (3.x) and `matplotlib` must also be installed.
*
Line plots
*
Histograms
*
Vertical, horizontal lines
*
Line segments
*
Plots as Base64
## examples
...
...
examples/README.md
View file @
3f71197d
...
...
@@ -102,4 +102,22 @@ figure.add_plot(mean_line);
figure
.save
(
"./examples/figures/horizontal_line.png"
,
None
);
```
![
plot
](
figures/horizontal_line.png
)
\ No newline at end of file
![
plot
](
figures/horizontal_line.png
)
## line segments
```
rust
let
x
=
vec!
[
1
,
2
,
3
,
4
];
let
y
=
vec!
[
0.1
,
0.2
,
0.5
,
0.3
];
let
mut
options
=
ScatterPlotOptions
::
new
();
options
.marker
=
Some
(
Markers
::
Diamond
);
let
lp
=
scatter_plot
::
<
i32
,
f64
>
(
x
,
y
,
Some
(
options
));
let
mut
figure
=
Figure
::
new
();
figure
.add_plot
(
lp
);
let
mut
line_opt
=
LinePlotOptions
::
new
();
line_opt
.colour
=
Some
(
"red"
.to_string
());
line_opt
.lineStyle
=
Some
(
LineStyle
::
Dash
);
figure
.add_plot
(
line
::
<
i32
,
f64
>
((
1
,
0.1
),
(
4
,
0.3
),
Some
(
line_opt
)));
```
![
plot
](
figures/line_segment.png
)
\ No newline at end of file
examples/figures/line_segment.png
0 → 100644
View file @
3f71197d
12.7 KiB
src/lib.rs
View file @
3f71197d
...
...
@@ -108,7 +108,7 @@ impl Figure {
pub
fn
new
()
->
Figure
{
return
Figure
{
script
:
"import matplotlib
\n
matplotlib.use('agg')
\n
import matplotlib.pyplot as plt
\n\n
"
.to_string
()
script
:
"import matplotlib
\n
matplotlib.use('agg')
\n
import matplotlib.pyplot as plt
\
n
from matplotlib.lines import Line2D
\
n\n
"
.to_string
()
}
}
...
...
@@ -276,6 +276,17 @@ pub fn vertical_line<U>(x: U, options: Option<LinePlotOptions>) -> String where
}
}
pub
fn
line
<
U
,
T
>
(
start
:
(
U
,
T
),
end
:
(
U
,
T
),
options
:
Option
<
LinePlotOptions
>
)
->
String
where
U
:
ToString
,
T
:
ToString
{
match
options
{
Some
(
opt
)
=>
{
return
format!
(
"ax=plt.gca()
\n
ax.add_line(Line2D([{},{}],[{},{}],{}))
\n
"
,
start
.0
.to_string
(),
end
.0
.to_string
(),
start
.1
.to_string
(),
end
.1
.to_string
(),
opt
);
},
None
=>
{
return
format!
(
"ax=plt.gca()
\n
ax.add_line(Line2D([{},{}],[{},{}]))
\n
"
,
start
.0
.to_string
(),
end
.0
.to_string
(),
start
.1
.to_string
(),
end
.1
.to_string
());
}
}
}
#[cfg(test)]
mod
lineplot
{
use
super
::
*
;
...
...
@@ -434,9 +445,22 @@ mod lineplot {
print!
(
"{:?}"
,
figure
.save
(
"./examples/figures/horizontal_line.png"
,
None
));
}
#[test]
fn
line_segment
()
{
let
x
=
vec!
[
1
,
2
,
3
,
4
];
let
y
=
vec!
[
0.1
,
0.2
,
0.5
,
0.3
];
let
mut
options
=
ScatterPlotOptions
::
new
();
options
.marker
=
Some
(
Markers
::
Diamond
);
let
lp
=
scatter_plot
::
<
i32
,
f64
>
(
x
,
y
,
Some
(
options
));
let
mut
figure
=
Figure
::
new
();
figure
.add_plot
(
lp
);
let
mut
line_opt
=
LinePlotOptions
::
new
();
line_opt
.colour
=
Some
(
"red"
.to_string
());
line_opt
.lineStyle
=
Some
(
LineStyle
::
Dash
);
figure
.add_plot
(
line
::
<
i32
,
f64
>
((
1
,
0.1
),
(
4
,
0.3
),
Some
(
line_opt
)));
figure
.save
(
"./examples/figures/line_segment.png"
,
None
);
print!
(
"{:?}"
,
figure
.script
);
}
}
fn
main
()
{
println!
(
"Hello, world!"
);
}
\ No newline at end of file