0

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

1
  • can you include sample data? Commented Mar 22, 2019 at 19:00

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.