[Python] Saving A plot using matplotlib, seaborn

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to plot Facet Grid, I have created whole function so it is more convenient, when I test it in my code editor it shows like it is in this

    [​IMG]

    , but when I actually save it is shown like this:

    [​IMG]

    , I need it to be saved exactly it is previewed not like reverted colors.

    I tried changing the background color of the grid and made it black and it was terrible didn't work the way I expected

    this is my current code:

    import seaborn as sns
    import matplotlib.pyplot as plt


    #################################### FACET ####################################
    def facet(data, x, y, col, hue, col_wrap=3, height=3, aspect=1.5, theme='dark',
    x_label=None, y_label=None, palette="crest", grid=True, save_path=None,
    background_opacity=0.2, back_line_color='.7'):

    # Set the theme for Seaborn plots
    sns.set_theme(style=theme)

    #### OTHER VISUALISATION CODE ###

    # Remove default titles from facets
    g.set_titles("")

    # Adjust layout to prevent overlap
    g.tight_layout()

    # Display the final plot
    plt.show()

    Continue reading...

Compartilhe esta Página