[Python] How to save matplotlib violinplots with axes? Tried using fig.tight_layout() but the...

Discussão em 'Python' iniciado por Stack, Novembro 26, 2024.

  1. Stack

    Stack Membro Participativo

    Thank you very much for helping out. I urgently need to solve this issue for my homework. My codes are as follows:

    import matplotlib.pyplot as pltimport numpy as np


    data_to_plot = [avg[0]['Cell Perimeter (unit pixel side)'], avg[1]['Cell Perimeter (unit pixel side)'], avg[2]['Cell Perimeter (unit pixel side)']]


    fig = plt.figure()ax = fig.add_axes([0,0,1,1])


    # Create the violinplot
    bp = ax.violinplot(data_to_plot)
    fig.tight_layout()
    plt.xticks([1, 2, 3], ['5.5', '12.5', '25'])
    plt.ylabel('Unit pixel side')
    plt.xlabel('Glucose concentration (mM)')
    plt.title('Cell perimeter axis distribution')
    fig.savefig('Cell perimeter distrution.tiff')
    plt.savefig('Cell perimeter distribution.jpg')
    plt.show()


    I tried adding fig.tight_layout(), but it is still not working, and gave me warning as follows:

    UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect. fig.tight_layout()

    I also tried fig.patch.set_facecolor('xkcd:white'), and it is not working.

    Thank you very much for helping out.

    Continue reading...

Compartilhe esta Página