How it works...

In step 1, we create another continuous variable by using pandas date functionality. This data was collected from the city of Houston on December 1, 2016. We use this date to determine how long each employee has worked for the city. When we subtract dates, as done in the second line of code, we are returned a Timedelta object whose largest unit is days. We could have simply divided this number by 365 to calculate the years of experience. Instead, we use Timedelta(1, unit='Y') to get a more precise measurement, which happens to be 365 days, 5 hours, 42 minutes and 19 seconds if you are counting at home.

Step 2 uses the seaborn Axes function regplot to create a scatter plot with the estimated regression line. It returns an Axes, which we use to change the size of the Figure. In order to create two separate regression lines for each gender, we must use its parent function, lmplot. It contains the hue parameter, which creates a new regression line for each unique value of that variable. At the end of step 3, we verify that lmplot does indeed return a seaborn Grid object.

The seaborn Grid is essentially a wrapper around the entire Figure, with a few convenience methods to alter its elements. All seaborn Grids may access the underlying Figure with their fig attribute. Step 4 shows a common use-case for seaborn Grid functions, which is to create multiple plots based on a third or even fourth variable. We set the col parameter to RACE. Six regression plots are created for each of the six unique races in the dataset. Normally, this would return a grid consisting of 1 row and 6 columns, but we use the col_wrap parameter to limit the number of columns to 3.

There are several more available parameters to control most of the important aspects of the Grid. It is possible to change use parameters from the underlying line and scatter plot matplotlib functions. To do so, set the scatter_kws or the line_kws parameters equal to a dictionary that has the matplotlib parameter as a string paired to the value you want it to be.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.244.217