When using Seaborn facetGrid plots. Is it possible to set the row variable label to the left (eg. as the first line of the two-line sub-plots y axes label)?
The default location is on the top as part of the sub-plot title. unfortunately the combined text sometimes gets too long to legitably fit into that crowded space. Then I tried to use margin_titles = True option when instantiate the facetGrid object. But in this case, the row variable label is outside to the right of the legend, which can be awkwardly too far from the chart.
So the possible easy ways to improve the aesthetic in my two-cent worth of thought:
margin_titles = True
and legend_out=True
Sorry, haven't accumulated enough points to be able to add a chart example.
FacetGrid object takes a dataframe as input and the names of the variables that will form the row, column, or hue dimensions of the grid. The variables should be categorical and the data at each level of the variable will be used for a facet along that axis.
To create two graphs, we can use nrows=1, ncols=2 with figure size (7, 7). Create a data frame with keys, col1 and col2, using Pandas. Use countplot() to show the counts of observations in each categorical bin using bars. Adjust the padding between and around the subplots.
The plots it produces are often called “lattice”, “trellis”, or “small-multiple” graphics. It can also represent levels of a third variable with the hue parameter, which plots different subsets of data in different colors.
Sure thing! Enumerating over the axes seems to work just fine.
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style='ticks', color_codes=True)
tips = sns.load_dataset('tips')
g = sns.FacetGrid(tips, col='time', row='sex')
g = g.map(plt.scatter, 'total_bill', 'tip', edgecolor='w')
for i, axes_row in enumerate(g.axes):
for j, axes_col in enumerate(axes_row):
row, col = axes_col.get_title().split('|')
if i == 0:
axes_col.set_title(col.strip())
else:
axes_col.set_title('')
if j == 0:
ylabel = axes_col.get_ylabel()
axes_col.set_ylabel(row.strip() + ' | ' + ylabel)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With