Reputation: 1690
Graphing with matplotlib I get this 4 histograms model:
Using Seaborn I am getting the exact graph I need but I cannot replicate it to get 4 at a time:
I want to get 4 of the seaborn graphs (image 2) in the format of the image 1 (4 at a time with the calculations I made with seaborn).
My seaborn code is the following:
import os
import re
import time
import ipdb
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
path_file = os.path.join(BASE_DIR, 'camel_product_list.csv')
gapminder = pd.read_csv(path_file)
print(gapminder.head())
df = gapminder
sns.distplot(df['average_histogram_ssim'], hist=True, kde = False, label='All values')
df = gapminder[gapminder.color == 'green']
# sns.distplot(df['lifeExp'], hist = True, kde = True, label='Only Matches')
sns.distplot(df['average_histogram_ssim'], hist_kws={"histtype": "step",
"linewidth": 3,
"alpha": 1, "color": "b"} ,
kde = False, label='Only Matches')
# Plot formatting
plt.legend(prop={'size': 12})
plt.title('ratio_image SSIM')
plt.xlabel('Data Range')
plt.ylabel('Density')
plt.show()
The names of the columns of the dataframe are:
'ratio_text','ratio_image', 'ratio_hist', 'ratio_sub', 'color'
I'm using the color column as a filter.
How can I get the 4 seaborn plots for ratio_text','ratio_image', 'ratio_hist', 'ratio_sub', filtered by all colors and green color?
Upvotes: 3
Views: 5361
Reputation: 10545
First define your grid of subplots and assign its four axes to an array ax
:
fig, ax = plt.subplots(2, 2)
Now you can pass the axes you want to plot on to the seaborn plotting function with the ax
keyword argument, e.g. for the first plot:
sns.distplot(df['average_histogram_ssim'], hist=True, kde=False, label='All values',
ax=ax[0, 0])
Same with ax=ax[0, 1]
for the upper right plots, and so on.
Upvotes: 5