# plot_smooth_hr()


Plot a smooth hazard ratio curve for a continuous covariate.


Usage

``` python
plot_smooth_hr(
    result,
    *,
    scale="log_hr",
    title=None,
    xlab=None,
    ylab=None,
    backend="altair",
    width=500,
    height=300,
)
```


Draws the estimated (log) hazard ratio as a smooth curve across the range of a continuous covariate, with a shaded pointwise confidence band. A horizontal reference line marks HR = 1 (log-HR = 0). The curve is produced by [CoxPH.smooth_hr()](CoxPH.md#greenwood.CoxPH.smooth_hr).


## Parameters


`result: Any`  
A [SmoothHRResult](SmoothHRResult.md#greenwood.SmoothHRResult) from [CoxPH.smooth_hr()](CoxPH.md#greenwood.CoxPH.smooth_hr).

`scale: str = ``"log_hr"`  
`"log_hr"` (default) plots the log hazard ratio. `"hr"` plots the hazard ratio.

`title: str | None = None`  
Optional title for the chart.

`xlab: str | None = None`  
Label for the x-axis. Defaults to the covariate name.

`ylab: str | None = None`  
Label for the y-axis. Defaults to `"Log hazard ratio"` or `"Hazard ratio"`.

`backend: Literal[``"altair", `<span class="st">`"plotnine"``]`</span>` = ``"altair"`  
Plotting backend: `"altair"` (default) or `"plotnine"`.

`width: int = ``500`  
Width in pixels (Altair) or approximate inches (plotnine).

`height: int = ``300`  
Height in pixels (Altair) or approximate inches (plotnine).


## Returns


`alt.Chart or plotnine.ggplot`  


## Examples


``` python
import greenwood as gw

lung = gw.load_dataset("lung", backend="polars")
y = gw.Surv.right(lung["time"], event=(lung["status"] == 2))
cox = gw.CoxPH().fit(y, lung[["age", "sex"]])

gw.plot_smooth_hr(cox.smooth_hr("age"))
```


<style>
  #altair-viz-7733f2b9def64a5387a38aedc7acc233.vega-embed {
    width: 100%;
    display: flex;
  }

  #altair-viz-7733f2b9def64a5387a38aedc7acc233.vega-embed details,
  #altair-viz-7733f2b9def64a5387a38aedc7acc233.vega-embed details summary {
    position: relative;
  }
</style>


Plot on the hazard ratio scale instead:


``` python
gw.plot_smooth_hr(cox.smooth_hr("age"), scale="hr")
```


<style>
  #altair-viz-c7968d37535248379ec6c267a617b86d.vega-embed {
    width: 100%;
    display: flex;
  }

  #altair-viz-c7968d37535248379ec6c267a617b86d.vega-embed details,
  #altair-viz-c7968d37535248379ec6c267a617b86d.vega-embed details summary {
    position: relative;
  }
</style>
