![]() Handles, labels = ax.get_legend_handles_labels()Īx. Move the location and make use of bbox_to_anchor to move outside the plot area (note that the bbox parameters need some tweaking depending on your plot size).Set a new title that is actually a title.Remove the default seaborn title, which is actually a legend entry, by getting and slicing the handles and labels.Sns.scatterplot(x = 'Sepal.Length', y = 'Sepal.Width', With a simple sns.scatterplot (the default type of plot used by sns.relplot), your code works (changed to use reproducible data): df = pd.read_csv("", index_col=0) Also, if you are using scatter plots, use scatterpoints1 rather than numpoints1 in the legend call to have only one point for each legend entry. The issue is that sns.relplot is a "Figure-level interface for drawing relational plots onto a FacetGrid" (see the API page). Using the scatter method of the matplotlib.pyplot module should work (at least with matplotlib 1.2.1 with Python 2.7.5), as in the example code below. How do I fix this such? My desired result is one graph where I can specify the figure dimensions and have the legend at the bottom in two rows, below the x-axis (if that is too difficult, or not supported, then the default legend position to the right on the same graph would work too)? I know the problem lies with "ax=ax", and in the way I am specifying the dimensions as matplotlib figure, but I'd like to know specifically why this causes a problem so I can learn from this. The result is two graphs - one that has the scatter plots as expected but missing the legend, and another one below it that is all blank except for the legend on the right hand side. ![]() However, when I try to generate a matplotlib figure and axes objects ahead of time to specify the figure dimensions I run into problems: a4_dims = (10, 10) # generating a matplotlib figure and axes objects ahead of time to specify figure dimensionsįig, ax = plt.subplots(figsize = a4_dims) The result is a scatter plot as desired, with the legend on the right hand side. ![]() When I do this simple way, everything works fine: import pandas as pd Handles, labels = ax.get_legend_handles_labels()Īx.I created a scatter plot in seaborn using seaborn.relplot, but am having trouble putting the legend all in one graph. I initially used lmplot () for the polynomial order. I am looking to plot both of them in the same graph but the dependent variables have different y-axes. Sns.scatterplot(data=df_points, x="x", y="y", hue="Series", ax=ax,s=200) I have 2 datasets (df3 and df4 which respectively hold information for total head and efficiency) with a common independent variable (flow rate). ![]() Sns.lineplot(data=df_dash,x="x",y="y", hue="Series dashed",ax=ax,palette="rocket",linewidth=2.5,linestyle="-") Plot_df_points = pd.DataFrame(index =, columns =, data=np.array(,]))ĭf = pd.DataFrame(plot_df.stack()).reset_index()ĭf_dash = pd.DataFrame(plot_df.stack()).reset_index()ĭf_lumns=ĭf_points = pd.DataFrame(plot_df_points.stack()).reset_index() Plot_df_dash = pd.DataFrame(index=np.arange(5), columns=, data=np.array(,])) Plot_df = pd.DataFrame(index=np.arange(5), columns=, data=np.array(,])) import pandas as pdįrom matplotlib.legend_handler import HandlerTuple I have two line charts consisting each of two lines. I have a question how to combine three plots with different linestyle and adjust the legend accordingly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |