Because of this, we need to be mindful of where we place the legend. We can also see that the legend now covers a data point. We can see that by passing in location of 1, that the location of the legend has changed to the top right. This returns the following visualization: Change Legend Position in Seaborn Using Numbered Positions In the code block above, we passed in the location of 1. # Moving a Legend in Seaborn Using Numbered Positions Similar to using named positions, we can also use numbered positions. We can see that the location of the legend has changed to the upper middle position. ![]() This returned the following visualization: Change Legend Position in Seaborn Using Named Positions We then used the plt.legend() function and passed in the 'upper center' into the loc= parameter. In the example below, we loaded the 'tips' dataset available in the Seaborn library and made a Seaborn scatterplot with the data. Sns.scatterplot(data=df, x='total_bill', y='tip', hue='day') # Moving a Legend in Seaborn Using Named Locations It will determine where the best location for the legend is, depending on where the data points are in the chart. By default, Seaborn will use a location of 'best' or 0. Let’s start by looking at named locations first, since they’re quite a bit more intuitive. The table below breaks down the different locations, both named and numbered, that are available: Location String The argument accepts both a named location as well as a numbered location. In order to move a legend location in Seaborn, use the loc= argument in the plt.legend() function. Let’s dive into how to move the legend location first. When you call the function, you can pass in various parameters that allow you to customize the legend. In general, you call the function as shown below: import seaborn as sns legend() function available in Matplotlib pyplot. ![]() ![]() In order to customize legends in Seaborn, you can use the.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |