


One solution is to set different loc variables in. legends() will result in one legend being on top of the other. However when it comes to scatter plots, these python libraries do not have any straight forward option to display labels of data points.
#Add legend to scatter plot matplotlib how to#
Seaborn library built over matplotlib has greatly improved the aesthetics and provides very sophisticated plots. Answers related to python scatter plot legend position matplotlib custom legend matplotlib legend out of plot how to add legend to python plot place. There is no default way to do this, and calling two. Matplotlib is very fast and robust but lacks the aesthetic appeal. One difficulty with this is creating a legend with both labels.

# Solution for having two legends leg = lns1 + lns2 labs = ax1.legend(leg, labs, loc=0) twinx() element, which makes the new axis share the old axes x-axis, but keeps an independent y-axis. Here’s a breakdown of how this works: ax2 = ax1.twinx() 5 ax1 = fig.add_axes() ax2 = fig.add_axes() # This is the magic that joins the x-axis ax2 = ax1.twinx() lns1 = ax1.plot(wnv3, color='blue', lw=line_weight, alpha=alpha, label='Mosquitos') lns2 = ax2.plot(wnv3, color='orange', lw=line_weight, alpha=alpha, label='Westnile') # Solution for having two legends leg = lns1 + lns2 labs = ax1.legend(leg, labs, loc=0) plt.title('Cumulative yearly mosquito & West Nile levels', fontsize=20) plt.show() to set title of our scatter plot plt.legend(loc1)loc is used to set. # Plot two lines with different scales on the same plot fig = plt.figure(figsize=(8, 5)) line_weight = 3 alpha =. Matplotlib Scatter, in this we will learn one of the most important plots used.
