How to plot 2 graphs using seaborn in Python 3.6?

I want the first subplot to only include 'Máximo', 'Média', 'Mínimo', and the second to only include 'Amplitude', 'Desvio Padrão'.

I tried the following:

def plotGraph(title, z): #Todo Completar a função com legendas e título.
    sns.set()
    fig, ax = plt.subplots(2,1)
    sns.lineplot(data=z, hue=['Máximo', 'Média', 'Mínimo'], ax=ax[0])
    sns.lineplot(data=z, hue=['Amplitude', 'Desvio Padrão'], ax=ax[1])
    plt.show()

But got this: image

I know I can make this with multiple calls using plt.plot(), but is there a way to do with seaborn?

         **EDITED**

thanks, but I realized I don't need 'Desvio Padrão'. Is there a way to just legend 'Amplitude' ?

def plotGraph(title, df): #Todo Completar a função com legendas e título.
    sns.set()
    fig, ax = plt.subplots(2,1)
    fig.suptitle(title)
    sns.lineplot(data=df[['Máximo', 'Média', 'Mínimo']], hue=['Máximo', 'Média', 'Mínimo'], ax=ax[0])
    sns.lineplot(data=df['Amplitude'], hue='Amplitude', ax=ax[1], legend='full')
    fig.tight_layout(rect=[0.01, 0.01, 0.95, 0.95])  # Controla o tamanho dos gŕaficos na figura (valores entre 0 e 1).
    plt.show()

enter image description here

Upvotes: 0

Views: 133

Answers (1)

Nathaniel
Nathaniel

Reputation: 3290

You need to subset the data frame to include only the columns you want to plot:

import pandas as pd
import numpy as np; np.random.seed(0)
import matplotlib.pyplot as plt
import seaborn as sns
import cufflinks as cf

# Generate sample data
df = cf.datagen.lines(5)
df.columns = ['Máximo', 'Média', 'Mínimo', 'Amplitude', 'Desvio Padrão']
df = df.reset_index(drop=True)

def plotGraph(title, z):
    sns.set()
    fig, ax = plt.subplots(2,1)
    fig.suptitle(title)
    sns.lineplot(data=z[['Máximo', 'Média', 'Mínimo']], hue=['Máximo', 'Média', 'Mínimo'], ax=ax[0])
    sns.lineplot(data=z[['Amplitude', 'Desvio Padrão']], hue=['Amplitude', 'Desvio Padrão'], ax=ax[1])
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    plt.show()

plotGraph('Plot Title', df)

Plot

Upvotes: 2

Related Questions