Matplotlib Tutorial 25 – customizing Matplotlib Legends




[ad_1]

In this Matplotlib tutorial, we’re going to be going over custom legends. We’ve covered the basics of adding a legend already.

The main issue with legends is typically that the legend gets in the way of data. There are a few options here. One option is to put the legend outside of the axis, but we have multiple subplots here and that would be pretty difficult. Instead, we’ll make the legend a bit smaller, and then apply an alpha to it.

First, to have a legend, we need to add labels to our data that we want to show up on the legend.

sample code: http://pythonprogramming.net
http://hkinsley.com
https://twitter.com/sentdex
http://sentdex.com
http://seaofbtc.com

Source


[ad_2]

Comment List

  • sentdex
    November 27, 2020

    Your videos are great! Sometimes I just think there is a bit too much talk in between unrelated things. Nice work and thanks!

  • sentdex
    November 27, 2020

    to add to my previous question, its a live chart which needs to refresh every tick. So there is the price data which is stored in MySql and a couple of algorithms running at the back end server and that data is stored in mysql tables. I need to plot the price on top and the all the other data below the price (using multiple y axis.) Thanks in advance.

  • sentdex
    November 27, 2020

    How do i plot this from a MySql database?

  • sentdex
    November 27, 2020

    3:19. With current version of Matplotlib (May 2018) you can just put add to ax_2v.fill_between option: label="something".

  • sentdex
    November 27, 2020

    I think that title of video should be "Matplotlib Tutorial 25 – Customizing Matplotlib legends". But these is minor detail.

  • sentdex
    November 27, 2020

    I have to put the savefig line ABOVE plt.show(). If I don't I get:

    _tkinter.TclError: can't invoke "wm" command: application has been destroyed

  • sentdex
    November 27, 2020

    Good work. I have two specific observations. If you have suggestions to circumvent please share.

    1. fig.savefig() saves only after program execution terminates
    .
    2. Because sub plot 2 is dual y axis, only x value is displayed at right corner (on mouse over /movement)

    Thanks
    Venkat

  • sentdex
    November 27, 2020

    Hasta este punto ha sido todo lo que he querido… Muchas gracias por todo el esfuerzo con estos tutoriales, son muy útiles.

    Until this point it has been everything I wanted… Thank you so much for all the effort put in those tutorials, they're very useful.

Write a comment