Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting different axis range for seaborn PairGrid

I am plotting using seaborn and I am using seaborn.PairGrid function. This is creating 6 x 6 grid, where diagonal plots are histograms and off diagonal plots are scatter plots. Now I want to have different y ranges for each row of plots and different x ranges for each column of the plots. I searched stack exchange a lot but could not find a way to achieve this. Matplot version is 2.0.0 and seaborn version is 0.7.1.

Thanks

like image 431
user9026 Avatar asked Apr 13 '17 04:04

user9026


People also ask

How do you plot more than one graph in Seaborn?

In Seaborn, we will plot multiple graphs in a single window in two ways. First with the help of Facetgrid() function and other by implicit with the help of matplotlib. data: Tidy dataframe where each column is a variable and each row is an observation.

What is PairGrid in Seaborn?

PairGrid allows us to draw a grid of subplots using the same plot type to visualize data. Unlike FacetGrid, it uses different pair of variable for each subplot. It forms a matrix of sub-plots. It is also sometimes called as “scatterplot matrix”. The usage of pairgrid is similar to facetgrid.


1 Answers

You can use the Axes.set_xlim() and Axes.set_ylim() methods on the axes of the seaborn PairGrid or FacetGrid. The axes are available from the PairGrid as .axes attribute.

import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g = g.map_diag(plt.hist, edgecolor="k")
g = g.map_offdiag(plt.scatter, s=10)

g.axes[2,0].set_ylim(-10,10)
g.axes[0,1].set_xlim(-40,10)

plt.show()
like image 105
ImportanceOfBeingErnest Avatar answered Sep 18 '22 16:09

ImportanceOfBeingErnest