pub struct SurvivalPlot {
pub groups: Vec<KMGroup>,
pub color: String,
pub group_colors: Option<Vec<String>>,
pub line_width: f64,
pub show_ci: bool,
pub ci_alpha: f64,
pub show_censoring: bool,
pub censoring_size: f64,
pub pvalue_text: Option<String>,
pub legend_label: Option<String>,
}Expand description
Builder for a Kaplan-Meier survival plot.
Each group produces a step-function survival curve, optional confidence
bands (Greenwood’s formula, linear scale), and optional censoring tick
marks. When multiple groups are present a log-rank p-value can be
annotated via with_pvalue_text.
§Example
use kuva::prelude::*;
let plot = SurvivalPlot::new()
.with_group("Treatment A", vec![5.0,8.0,12.0,15.0,20.0], vec![true,true,false,true,false])
.with_group("Treatment B", vec![3.0,6.0,9.0,14.0,18.0], vec![true,false,true,true,false])
.with_ci(true)
.with_legend("Group");
let plots = vec![Plot::from(plot)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Overall Survival")
.with_x_label("Time (months)")
.with_y_label("Survival probability");Fields§
§groups: Vec<KMGroup>§color: StringFallback line color when no per-group colors are set and no palette is active.
group_colors: Option<Vec<String>>Per-group color overrides (indexed by group order).
line_width: f64Line stroke width in pixels. Default 2.0.
show_ci: boolDraw Greenwood 95% CI bands. Default false.
ci_alpha: f64Opacity of CI bands. Default 0.2.
show_censoring: boolDraw censoring tick marks on the curves. Default true.
censoring_size: f64Half-height of censoring ticks in pixels. Default 4.0.
pvalue_text: Option<String>Optional p-value / annotation text rendered in the upper-right of the plot area.
legend_label: Option<String>Implementations§
Source§impl SurvivalPlot
impl SurvivalPlot
Sourcepub fn with_group(
self,
label: impl Into<String>,
times: Vec<f64>,
events: Vec<bool>,
) -> Self
pub fn with_group( self, label: impl Into<String>, times: Vec<f64>, events: Vec<bool>, ) -> Self
Add a group with separate time and event vectors.
times: time to event or censoring. events: true = event occurred.
Sourcepub fn with_colored_group(
self,
label: impl Into<String>,
times: Vec<f64>,
events: Vec<bool>,
color: impl Into<String>,
) -> Self
pub fn with_colored_group( self, label: impl Into<String>, times: Vec<f64>, events: Vec<bool>, color: impl Into<String>, ) -> Self
Add a group with a per-group color override.
Sourcepub fn with_color(self, color: impl Into<String>) -> Self
pub fn with_color(self, color: impl Into<String>) -> Self
Set the fallback line color. Default "steelblue".
Sourcepub fn with_group_colors(
self,
colors: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_group_colors( self, colors: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set per-group colors (indexed by group order). Falls back to category10.
Sourcepub fn with_line_width(self, w: f64) -> Self
pub fn with_line_width(self, w: f64) -> Self
Set line stroke width in pixels. Default 2.0.
Sourcepub fn with_ci(self, show: bool) -> Self
pub fn with_ci(self, show: bool) -> Self
Show 95% confidence bands (Greenwood’s formula). Default false.
Sourcepub fn with_ci_alpha(self, alpha: f64) -> Self
pub fn with_ci_alpha(self, alpha: f64) -> Self
Set confidence band opacity. Default 0.2.
Sourcepub fn with_censoring(self, show: bool) -> Self
pub fn with_censoring(self, show: bool) -> Self
Show censoring tick marks on curves. Default true.
Sourcepub fn with_censoring_size(self, size: f64) -> Self
pub fn with_censoring_size(self, size: f64) -> Self
Set the half-height of censoring tick marks in pixels. Default 4.0.
Sourcepub fn with_pvalue_text(self, text: impl Into<String>) -> Self
pub fn with_pvalue_text(self, text: impl Into<String>) -> Self
Add a p-value or annotation string rendered in the upper-right corner.
Typical use: with_pvalue_text("p = 0.023") or "log-rank p < 0.001".
Sourcepub fn with_legend(self, label: impl Into<String>) -> Self
pub fn with_legend(self, label: impl Into<String>) -> Self
Attach a legend to this plot (shows one entry per group).
Trait Implementations§
Source§impl Default for SurvivalPlot
impl Default for SurvivalPlot
Source§impl From<SurvivalPlot> for Plot
impl From<SurvivalPlot> for Plot
Source§fn from(p: SurvivalPlot) -> Self
fn from(p: SurvivalPlot) -> Self
Auto Trait Implementations§
impl Freeze for SurvivalPlot
impl RefUnwindSafe for SurvivalPlot
impl Send for SurvivalPlot
impl Sync for SurvivalPlot
impl Unpin for SurvivalPlot
impl UnsafeUnpin for SurvivalPlot
impl UnwindSafe for SurvivalPlot
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
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.