appkeron.blogg.se

Add legend to scatter plot matplotlib
Add legend to scatter plot matplotlib




add legend to scatter plot matplotlib

+premium, = plt.plot(year, tutorial_premium, color="#f3e151", linewidth=3) +public, = plt.plot(year, tutorial_public, color="#6c3376", linewidth=3) Then, you pass it as a list to legend() with your labels (also as a list). Instead of declaring them during the plot() call, you could save the first returning object. There is an alternative way to set the labels. +plt.plot(year, tutorial_premium, label='Premium Tutorials', color="#f3e151", linewidth=3) +plt.plot(year, tutorial_public, label='Public Tutorials', color="#6c3376", linewidth=3) The easiest way to do this is by passing an additional parameter during the plot() call: # add label parameter for easy legend generation Thus, you have to set a label for each line.

#Add legend to scatter plot matplotlib how to

The problem is that matplotlib doesn't know how to describe the plotted lines. However, if you would do that with the above code, matplotlib would fail to generate a legend. legend(): plt.plot(year, tutorial_public, color="#6c3376", linewidth=3) In general, you add a legend with matplotlib by calling. In the current version, the plot doesn't explain what the purple and yellow lines stand for: Plt.ylabel('Number of futurestud.io Tutorials') Plt.plot(year, tutorial_premium, color="#f3e151", linewidth=3) Plt.plot(year, tutorial_public, color="#6c3376", linewidth=3)

add legend to scatter plot matplotlib

The plot you will be working with in this tutorial is (again) a line plot with the number of tutorials we have published on Future Studio in the past years: # data Getting Started with High-Quality Plots in Python






Add legend to scatter plot matplotlib