- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create a dataframe with col1 columns.
- Multi-plot grid for plotting conditional relationships.
- Use map_dataframe(). This method is suitable for plotting with functions that accept a long-form DataFrame as a 'data' keyword argument and access the data in that DataFrame using string variable names.
- Add a legend to the plot().
- To display the figure, use show() method.
Example
import pandas as pd import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'col1': [3, 7, 8]}) g = sns.FacetGrid(df, col="col1", hue="col1") g.map_dataframe(sns.scatterplot) g.set_axis_labels("X", "Y") g.add_legend() plt.show()
Output
- Related Articles
- How to make a heatmap square in Seaborn FacetGrid using Matplotlib?
- Add minor gridlines to Matplotlib plot using Seaborn
- How to place customized legend symbols on a plot using Matplotlib?
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?
- Plotting error bars from a dataframe using Seaborn FacetGrid (Matplotlib)
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to increase the font size of the legend in my Seaborn plot using Matplotlib?
- How to add percentages on top of bars in Seaborn using Matplotlib?
- How to plot a dashed line on a Seaborn lineplot in Matplotlib?
- Set Max value for color bar on Seaborn heatmap using Matplotlib
- Add a custom border to certain cells in a Matplotlib / Seaborn plot
- Plot a bar using matplotlib using a dictionary
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How to create a legend for a 3D bar in Matplotlib?
- How to add a legend to a Matplotlib pie chart?

Advertisements