Step 1: Create your pandas DataFrame
We’ll import the pandas library and create our DataFrame:
import pandas as pd
area = ['Python', 'Python', 'R', 'Javascript', 'Python', 'R']
hired = [ 12, 14, 11, 12, 14, 18]
applications = [82, 73, 59, 67, 80, 90]
campaign = dict(area = area, hired = hired, apps = applications)
hired_df = pd.DataFrame(data=campaign)
hired_df.head(
Step 2: Plot your Scatter chart
We will start by creating a scatter plot our of our DataFrame. Note that we are using the scatter chart for convenience, but you can apply this tutorial to any type of chart such as bar, column, box, line, histograms etc’.
hired_df.plot(y ='hired', x= 'apps',kind='scatter', title = 'Hired vs Applicants');
The chart figure is probably a bit large and needs to be adjusted. The default size of your charts is [6.4, 4.8] inches. First number is the plot width and second is the height.
Note: different matplotlib parameters including the figure size, fonts and different chart settings are available for you to look into using the following code:
import matplotlib.pyplot as plt
plt.rcParams
Step 3: Adjust the size of your chart
To modify your chart width and height, we will tweak the figsize parameter of our chart. We will also tweak the market sign and color.
hired_df.plot(y ='hired', x= 'apps',kind='scatter', title = 'Hired vs Applicants',figsize= (6,3), marker='x', color = 'green',);
Step 4: Change font text size
We can also override the default text size and increase our chart title and axis label fonts.,
hired_plot = hired_df.plot(y ='hired', x= 'apps',kind='scatter', marker='x', color = 'green' ,figsize= (6,3));
hired_plot.set_title('Hired vs Applicants', fontsize=14) # resize title
hired_plot.set_xlabel('Applicants',fontsize=12) # size label font x axis
hired_plot.set_ylabel('Hired',fontsize=12); # size label font y axis
Here’s our chart: