Matplotlib Secondary y-Axis || Add another y-axis with Matplotlib twinx || Matplotlib Tips

preview_player
Показать описание
Learn how to make a Matplotlib secondary y axis in this Matplotlib Tips tutorial video. I start from the basics and show you how to add another y axis with the matplotlib twinx axes method. I explain that you should consider matplotlib two y axes if your data are on two different scales. Then we learn how to use ax twinx, which creates a new set of subplot axes with an invisible x-axis but an independent y axis on the opposite side. I them demonstrate how you can color code your matplotlib secondary y axis ticks and label to make your visual more clear. I also show you code for creating a matplotlib secondary y axis legend, both as separate legends for each axis and as one ax twinx legend. I then walk you through an example of creating a seaborn secondary y axis, which means you can have seaborn two y axes as well also using plt twinx. Finally, I conclude by showing visuals of a matplotlib figure with three y axes and a matplotlib secondary x-axis using matplotlib twiny.

0:00 Introduction
0:18 BASICS: matplotlib twinx
4:53 COLOR CODE: labels, ticks, spines
8:10 LEGEND: ax twinx legend
10:52 SEABORN twinx
12:28 Other Options: 3 y-Axes and twiny
13:12 BLOOPERS

GitHub Code:

Related Videos:

#matplotlib #dataviz
Рекомендации по теме
Комментарии
Автор

Kimberly, I think you should be given a noble price of teaching. I love your way of driving the concepts home, your energy and your enthusiasm. You're the best.

youcefyahiaoui
Автор

Thank you. I initially came to learn how `twinx` works, but I ended up learning a lot of other helpful things as well. I'm subscribing 🙂.

salmansiddiqui
Автор

Extraordinary!!! I love how you explain everything concisely. Thank you very much for the video ❤️

sandfly
Автор

Was hung up on the legend overlapping for a bit, thanks

nicholasrice
Автор

Neat!!!!
Thank you so much for sharing this content.
It really made my life easier here.
Cheers!!!!

vitorribeirosa
Автор

Thanks it helped!
w.r.t time = 6:43
Just adding another tip for someone in future (maybe myself :D)
Rather than using 'labelcolor' in ax.tickparams(), you could use 'colors' to set the ticks along with the label to the same color instead of the default black
Cheers!

nilakanthasahoo
Автор

Beautifully explained by a beautiful lady👏

vijaygusain
Автор

Thank you for the clear and precise tutorials!

heliumbite
Автор

Excellent video ! Very clear and informative as always.. thank you so much for this Tips series !

joseantonioubeira
Автор

Your videos are the best I've ever seen in this field, but I have a question:
have You thought about making videos which showing plotly library?
It would be amazing in Your performance. Cheers :)

ksawerylejczak
Автор

Hii mam could you show the samething in a subplot?

ndeye
Автор

Thank you so much! This is a big help!

jas
Автор

Kimberly, is there a way to connect the data points of the spines to each other? For example, if I have a data of 10 rows and 4 columns. In which each column is a separate y axis with its own scale while each row is a single observation, is there a way to connect the data points of a single observation with a line even though they have separate y axis?

MM-jxrw
Автор

Hello, can you please do a video about bias and variance, you have a good way of explanation.
Thank you :)

houriabraikia
Автор

can you make a video or update code at your Github for how to split single y-axis in two portions۔ for example plot X and its square on the same axis with partition

ahsanulhaq
Автор

How do you prevent the figure from expanding horizontally when using twinx? I set my figure dimensions in the main figure, let's say 8.4 by 6.2 centimeters. The first figure is added as a subplot, and the twinx is added to this subplot. Without the twinx, the figure nicely scales to 8.4 to 6.2 cm as desired. When adding the twinx, the figure expands by at least 1 extra cm.

ThaFuzzwood
Автор

Thanks for this Video, but why the line does not start at the x = 0 | y = 0

when you define the variable x and y with linespace(0, 100, 1000), the 0 is included as a x[0] and y[0] but i can not udnestand why when i plot it the line start after a space, i know it is a 0, 0 in the chart, but how can i fix this?.

Is my question clear? haha

Thx!

Niconico
visit shbcf.ru