vegas-viz / Vegas

The missing MatPlotLib for Scala + Spark
MIT License
730 stars 99 forks source link

Support for CDF? #119

Open yjk21 opened 6 years ago

yjk21 commented 6 years ago

Great project! Does it support generating cumulative distribution function plots, like in pyplot (e.g. https://matplotlib.org/examples/statistics/histogram_demo_cumulative.html)? Thanks

mgoeminne commented 6 years ago

Hello,

I don't reckon the lib supports cdf, per se, but you can definitely plot something that looks like your figure.

For plotting survival estimates, I use something like

Vegas.layered("Kaplan-Meier")
         .withDataFrame(cat_model)
         .withLayers(
            Layer() 
               .mark(Area)     
               .encodeX("event_at", axis=Axis(title=x_label))
               .encodeY("lower_ci", axis=Axis(title="Survival"))
               .encodeY2("upper_ci")
               .encodeColor(category_name, Nominal)
               .configMark(opacity=opacity, interpolate=StepBefore),
           Layer()
              .mark(Line)
              .encodeX("event_at", Quant)
              .encodeY("estimate", Quant)
              .encodeColor(category_name, Nominal)
              .configMark(interpolate=StepBefore)
        )

So, basically, I use interpolate=StepBefore for getting the "cdf effect".

survival per regime