pub enum ColorType<T = String> {
Show 13 variants
RGBString(T),
RGBInteger(ColorComponent, ColorComponent, ColorComponent),
ARGBInteger(ColorComponent, ColorComponent, ColorComponent, ColorComponent),
VariableRGBInteger(Vec<RGBInts>),
VariableARGBInteger(Vec<ARGBInts>),
PaletteFracColor(f64),
PaletteCBColor(f64),
VariablePaletteColor(Vec<f64>),
SavedColorMap(T, Vec<f64>),
Index(ColorIndex),
VariableIndex(Vec<ColorIndex>),
Background,
Black,
}Expand description
Option type (for plots, borders, and text) that allows the various different gnuplot color formats. The gnuplot colorspec reference also explains these.
NOTE: Gnuplot interprets the alpha channel in an unusual way, where 0 is fully opaque and 255 is fully transparent. This wrapper inverts the meaning (as described below) to match the more common interpretation.
There are many equivalent ways of specifying colors, and this allows the user to chose the most convenient.
For example, all the following will produce the same blue color:
RGBColor("blue".into()), RGBColor("0x0000ff".into()), RGBColor("#0000ff".into()), RGBColor("0xff0000ff".into()),
RGBColor("#ff0000ff".into()), RGBIntegerColor(0, 0, 255), ARGBColor(255, 0, 0, 255),
See example usages of these colors in color.rs and variable_color.rs in the
Examples folder on Github
Variants§
RGBString(T)
string (&str or String, but usually created with &str) in one of the following gnuplot-supported formats
- colorname — e.g. “blue” [See the gnuplot list of colornames]
- 0xRRGGBB — string containing hexadecimal constant
- 0xAARRGGBB — string containing hexadecimal constant
- #RRGGBB — string containing hexadecimal in x11 format
- #AARRGGBB — string containing hexadecimal in x11 format
“#AARRGGBB” represents an RGB color with an alpha channel value in the high bits. An alpha value of 255 (FF) represents a fully opaque color; i.e., “#FFRRGGBB” is the same as “#RRGGBB”. An alpha value of 0 represents full transparency.
RGBInteger(ColorComponent, ColorComponent, ColorComponent)
tuple of u8 representing red, green and blue values as 0-255
ARGBInteger(ColorComponent, ColorComponent, ColorComponent, ColorComponent)
tuple of u8 representing alpha, red, green and blue values as 0-255.
As with RGBColor, an alpha value of 255 (FF) represents a fully opaque color;
an alpha value of 0 represents full transparency.
VariableRGBInteger(Vec<RGBInts>)
Vector of tuples of u8 (as per RGBColor), but instead of a single color for the whole
plot, the vector should contain a separte color for each data point.
VariableARGBInteger(Vec<ARGBInts>)
Vector of tuples of u8 (as per ARGBColor), but as with VariableRGBColor, a separate
color value is given for each data point.
PaletteFracColor(f64)
Sets the color of the plot element to a value picked from the current palette (see
set_palette()). The value supplied to this color type
selects the color within the color range of the palette: i.e. it if the color bar range had been
set with ax.set_cb_range(Fix(min), Fix(max)), the value would be expected to be between
min and max.
Example of usage is give in the color example.
Compare with PaletteFracColor
PaletteCBColor(f64)
Sets the color of the plot element to a value picked from the current palette (see
set_palette() . The value supplied to this color type
selects the color as a fraction of the current color range i.e. it is expected to be
between 0 and 1.
Example of usage is give in the color example.
Comparing with PaletteCBColor: given the following code
use gnuplot::{PaletteCBColor, PaletteFracColor, Fix, Figure, AxesCommon, Color};
assert!(frac >= 0.0);
assert!(frac <= 1.0);
let mut fg = Figure::new();
let ax = fg.axes2d();
ax.set_cb_range(Fix(min), Fix(max));
let col1 = Color(PaletteFracColor(frac));
let cb_range = max - min;
let col2 = Color(PaletteCBColor(min + (frac * cb_range)));
ax.lines(x, y, &[col1]);
ax.lines(x, y, &[col2]);the two lines should give the same color for any values of max and min, and 0 <= frac <= 1.
VariablePaletteColor(Vec<f64>)
Vector of f64 values which act as indexes into the current palette to set the color of
each data point. These variable values work in the same was as the single fixed value supplied
to a PaletteCBColor
SavedColorMap(T, Vec<f64>)
Similar to VariablePaletteColor in that it takes a Vec<f64> to set the indexes into the
color map for each data point, but in addition to the color data it takes a string hold the name
of the colormap to use. This should have been previously created in the workspace using the
create_colormap() function.
Index(ColorIndex)
Set the color of all elements of the plot to the nth color in the current gnuplot color cycle.
VariableIndex(Vec<ColorIndex>)
A color type that sets the color per element using a index n which represents the nth
color in the current gnuplot color scheme. In gnuplot this is the last element in the plot command,
in Rust gnuplot, the color type takes a vector of u8, where each index is treated the same as the
fixed IndexColor.
This is useful for setting bars/boxes etc to be
the same color from multiple plot commands. The variable_color example has examples of this usage.
Background
Set the color of the plot to the current background color.
Black
Fixed black color
Implementations§
Trait Implementations§
Source§impl<T> From<(u8, u8, u8)> for ColorType<T>
impl<T> From<(u8, u8, u8)> for ColorType<T>
Source§fn from(value: RGBInts) -> Self
fn from(value: RGBInts) -> Self
Converts (u8, u8, u8) into RGBInteger
Source§impl<T> From<(u8, u8, u8, u8)> for ColorType<T>
impl<T> From<(u8, u8, u8, u8)> for ColorType<T>
Source§fn from(value: ARGBInts) -> Self
fn from(value: ARGBInts) -> Self
Converts (u8, u8, u8, u8) into ARGBInteger
Source§impl<T> From<Vec<u8>> for ColorType<T>
impl<T> From<Vec<u8>> for ColorType<T>
Source§fn from(value: Vec<ColorIndex>) -> Self
fn from(value: Vec<ColorIndex>) -> Self
Converts Vec<u8> into VariableIndex
Source§impl<T> From<u8> for ColorType<T>
impl<T> From<u8> for ColorType<T>
Source§fn from(value: ColorIndex) -> Self
fn from(value: ColorIndex) -> Self
Converts u8 into Index