top of page

Python Data Analysis Tips - Plot on both left and right axis in Pandas

Updated: Aug 21, 2023


free, free academic, instruct, instructional, instructional education, free python learn, seaborn, python, data analysis, analysis, project, data analysis project, pandas, analyze, statical analysis
plot on dual y axis in Pandas


in Python Pandas is the fastest and easiest to use plotting in python, this is especially true if you already happen to by using a Pandas DataFrame. And 90% of a data scientist's work is manipulating a Pandas DataFrame as your work with the data you are putting into your Sklearn model.


Pandas make it easier to plot different scales together as well. Here we have two continuous features but unfortunately, if we wanted to plot them together the different scales of features make plotting very difficult to gain insights when plotted on the same axis.



We can fix the issue created by plotting different scales on the same y-axis by splitting the axis or in other words plotting on the right axis with the second feature.


Learn how to plot one continuous feature on the left axis and one continuous feature on the right axis. This will help with your data analysis and enable you to inspect the pattern between features now that the scale isn't obscuring the patterns.







Follow Data Science Teacher Brandyn





dataGroups:












free, free academic, instruct, instructional, instructional education,free python learn, seaborn, python, data analysis, analysis, project, data analysis project, pandas, analyze, statical analysis
use secondary_y argument to plot


Pandas makes it quick and easy to plot two features of different scales together. First, we need to plot one feature like we normally would however here we save the plot to a variable commonly called ax. Then we called Pandas plot function to a second time this time referencing the ax variable and assigning it to the ax argument. This essentially stacks the second plot on top of the first but to change the axis to the right side we call the argument secondary_y = True. This will plot the second call on the right axis and leave the original on the left axis.



This can be valuable in data analysis in Python as you can look for patterns on how observations move and flow together or not. In a time series analysis, this can be very valuable.




622 views1 comment
bottom of page