pub struct RGBAColor {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: f64,
}Expand description
RGBA color representation.
Fields§
§r: u8§g: u8§b: u8§a: f64Implementations§
Source§impl RGBAColor
impl RGBAColor
Sourcepub fn new(r: u8, g: u8, b: u8) -> Self
pub fn new(r: u8, g: u8, b: u8) -> Self
Examples found in repository?
examples/continuous_color.rs (line 41)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Generate scatter data with a continuous variable for color
6 let x: Vec<f64> = (0..200)
7 .map(|i| {
8 let t = i as f64 * 0.05;
9 t.cos() * (1.0 + t * 0.3)
10 })
11 .collect();
12 let y: Vec<f64> = (0..200)
13 .map(|i| {
14 let t = i as f64 * 0.05;
15 t.sin() * (1.0 + t * 0.3)
16 })
17 .collect();
18 let z: Vec<f64> = (0..200).map(|i| i as f64 * 0.05).collect();
19
20 let df = df! {
21 "x" => &x,
22 "y" => &y,
23 "z" => &z,
24 }?;
25
26 // Default blue-to-red gradient
27 GGPlot::new(df.clone())
28 .aes(Aes::new().x("x").y("y").color("z"))
29 .geom_point()
30 .title("Continuous Color (default gradient)")
31 .xlab("X")
32 .ylab("Y")
33 .save("continuous_color.svg")?;
34
35 println!("Saved continuous_color.svg");
36
37 // Custom gradient: dark blue to yellow
38 GGPlot::new(df)
39 .aes(Aes::new().x("x").y("y").color("z"))
40 .geom_point()
41 .scale_color_gradient(RGBAColor::new(10, 30, 100), RGBAColor::new(255, 230, 50))
42 .title("Continuous Color (custom gradient)")
43 .xlab("X")
44 .ylab("Y")
45 .save("continuous_color_custom.svg")?;
46
47 println!("Saved continuous_color_custom.svg");
48 Ok(())
49}More examples
examples/color_palettes.rs (line 63)
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Generate grouped scatter data
6 let groups = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon"];
7 let mut x_vals = Vec::new();
8 let mut y_vals = Vec::new();
9 let mut group_vals = Vec::new();
10
11 for (gi, &group) in groups.iter().enumerate() {
12 for j in 0..20 {
13 let base_x = gi as f64 * 2.0 + 1.0;
14 let base_y = (gi as f64 + 1.0) * 3.0;
15 let r = ((gi * 20 + j) * 7 + 13) % 17;
16 x_vals.push(base_x + (r as f64 / 17.0 - 0.5) * 2.0);
17 y_vals.push(base_y + ((r * 3 + 5) % 11) as f64 / 11.0 * 4.0 - 2.0);
18 group_vals.push(group);
19 }
20 }
21
22 let df = df! {
23 "x" => &x_vals,
24 "y" => &y_vals,
25 "group" => &group_vals,
26 }?;
27
28 // Viridis palette
29 GGPlot::new(df.clone())
30 .aes(Aes::new().x("x").y("y").color("group"))
31 .geom_point()
32 .scale_color_viridis()
33 .title("Viridis Palette")
34 .save("palette_viridis.svg")?;
35
36 println!("Saved palette_viridis.svg");
37
38 // Brewer Set1 palette
39 GGPlot::new(df.clone())
40 .aes(Aes::new().x("x").y("y").color("group"))
41 .geom_point()
42 .scale_color_brewer(PaletteName::Set1)
43 .title("Brewer Set1 Palette")
44 .save("palette_brewer_set1.svg")?;
45
46 println!("Saved palette_brewer_set1.svg");
47
48 // Brewer Dark2 palette
49 GGPlot::new(df.clone())
50 .aes(Aes::new().x("x").y("y").color("group"))
51 .geom_point()
52 .scale_color_brewer(PaletteName::Dark2)
53 .title("Brewer Dark2 Palette")
54 .save("palette_brewer_dark2.svg")?;
55
56 println!("Saved palette_brewer_dark2.svg");
57
58 // Manual colors
59 GGPlot::new(df)
60 .aes(Aes::new().x("x").y("y").color("group"))
61 .geom_point()
62 .scale_color_manual(vec![
63 ("Alpha", RGBAColor::new(255, 0, 0)),
64 ("Beta", RGBAColor::new(0, 180, 0)),
65 ("Gamma", RGBAColor::new(0, 0, 255)),
66 ("Delta", RGBAColor::new(255, 165, 0)),
67 ("Epsilon", RGBAColor::new(128, 0, 128)),
68 ])
69 .title("Manual Color Scale")
70 .save("palette_manual.svg")?;
71
72 println!("Saved palette_manual.svg");
73 Ok(())
74}pub fn with_alpha(self, a: f64) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RGBAColor
impl RefUnwindSafe for RGBAColor
impl Send for RGBAColor
impl Sync for RGBAColor
impl Unpin for RGBAColor
impl UnsafeUnpin for RGBAColor
impl UnwindSafe for RGBAColor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more