[Python] How to plot a scatter box plot on subplots on matplotlib

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to plot scatter data over the box plot of that data to show where each point lies. I have found a good solution to this on this previous question: Adding a scatter of points to a boxplot using matplotlib Using Jakob's method of defining a function and then calling this.

    The issue arises when I try to plot this on multiple subplots - the top subplot doesn't show the scatter points, but the bottom one does.

    [​IMG]

    The code I've used is:

    fig, ax = plt.subplots(2, figsize=(12, 8), sharex=True)
    ax[0].scattered_boxplot(x=data, boxprops=boxprops, flierprops=flierprops)
    ax[1].scattered_boxplot(x=data2, boxprops=boxprops, flierprops=flierprops)


    I have defined the scattered_boxplot function as shown in the previous question. How do I resolve this so that both subplots show the scatter data?

    Many thanks

    Continue reading...

Compartilhe esta Página