Plotting
========

``corr_vars.plot`` draws cohort figures with matplotlib.

Flowcharts
----------

.. currentmodule:: corr_vars.plot.flowchart

.. automodule:: corr_vars.plot.flowchart

Most studies never call these functions directly:
:meth:`Cohort.to_figureone() <corr_vars.core.cohort.Cohort.to_figureone>` draws the
cohort's inclusion/exclusion steps and passes its keyword arguments on.

.. code-block:: python

    # Cascade: every step, each with what it removed
    fig = cohort.to_figureone()

    # Trial profile, split into arms by a column of obs, saved as PDF
    fig = cohort.to_figureone(
        layout="profile",
        groupby="sex",
        group_labels={"M": "Male", "F": "Female"},
        output_file="flowchart.pdf",
    )

    # Style fields of FlowchartStyle can be passed the same way
    fig = cohort.to_figureone(thousands_sep="'", page_width=7.0)

.. currentmodule:: corr_vars.core.change_tracker

.. automethod:: ChangeTrackerPipeline.create_flowchart

.. currentmodule:: corr_vars.plot.flowchart

.. autofunction:: cascade_flowchart

.. autofunction:: profile_flowchart

.. autofunction:: profile_counts

.. autoclass:: ProfileCounts
   :members:

.. autoclass:: FlowchartStyle
   :members:

Movements
---------

.. currentmodule:: corr_vars.plot.movement

:func:`plot_movements` draws the ICU stays of one hospital case on a timeline,
one lane per ICU stay. It needs a cohort with ``obs_level="icu_stay"``.

.. code-block:: python

    from corr_vars.plot.movement import plot_movements

    case_id = cohort.obs["case_id"][0]
    fig = plot_movements(cohort, case_id)
    fig.savefig("movements.png", dpi=150)

.. autofunction:: plot_movements
