[Python] How to place on a caption on a code-generated figure in Markdown

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    The answers I have seen for figure captions assume you're inserting an image file. In my case I'm generating a plot with code and would like to be able to put a caption on it.

    I'm working in R Studio but the code itself is Python. Using Pandoc to ultimately generate a pdf.

    So if I have this code chunk

    ```{python residual_predicted_plot, echo=FALSE}
    fig, ax = plt.subplots(figsize=(5,3))
    sns.scatterplot(x=model3.predict(), y=model3.resid, ax=ax)
    xlim = ax.get_xlim()
    ax.axvline(x=xlim[0] + 1/3*(xlim[1]-xlim[0]), color='orchid', linestyle='--')
    ax.axvline(x=xlim[0] + 2/3*(xlim[1]-xlim[0]), color='orchid', linestyle='--')
    ax.axhline(y=0, color='orchid', linestyle='--')
    ax.set_xlabel('$\hat{y}$')
    ax.set_ylabel('$\epsilon$')
    ax.set_title('Residual vs. Predicted Scatterplot')

    plt.show()
    ```


    It produces this plot

    [​IMG]

    How can I get a caption associated with it?

    Continue reading...

Compartilhe esta Página