Come plottare dei dati in una window usando seaborn e matplotlib

APPUNTI, ESEMPI, SVILUPPO SW, TUTORIAL

Di seguito un piccolo esempio utile per capire come salvare su file e plottare in una finestra  dei dati con matplotlib elaborati tramite  seaborn.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import sys

def create_random_pandas_dataframe():

    """Create a random pandas dataframe"""

    df = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=list('ABCD'))

    return df

# Read in the data

if len(sys.argv) > 1:

    df = pd.read_csv(sys.argv[1])

else:

    df = create_random_pandas_dataframe()

    print(df)

# Plot the data

sns.set_style('whitegrid')

sns.set_palette('colorblind')

sns.pairplot(df)

# Save the plot

plt.savefig('test_sns.png')

# Show the plot

plt.show()

 

di seguito il risultato dell’esempio:

 

Se vuoi farmi qualche richiesta o contattarmi per un aiuto riempi il seguente form

    0 0 votes
    Article Rating
    Subscribe
    Notificami
    guest
    0 Commenti
    Inline Feedbacks
    View all comments
    0
    Would love your thoughts, please comment.x