TWO STYLES OF PLOTTING WITH MATPLOTLIB

There are two styles of plotting with matplotlib. They are as follows

  1. Plotting using SCRIPTING LAYER (Procedural method)
  2. Plotting using ARTIST LAYER (Object Oriented method)
 Lets see the scripting layer and artist layer with an example.


1. Plotting using SCRIPTING LAYER (Procedural method)
  • this is very commonly and widely used procedural method
  • using matplotlib.pyplot as plt
  • use plt to represent the title, xlabel, ylabel etc.,

Example:

df_a.plot(kind='area', alpha=0.35, figsize=(20,10))
plt.title('The Chart Title')
plt.xlabel('x-axis name')
plt.title('y-axis name') 
plt.show( )

2. Plotting using ARTIST LAYER (Object Oriented method)
  • this is object oriented procedure
  • using axes instances of your current plot and store it in a variable (Example: ax)
  • syntax: variable.set_

Example:

ax=df_a.plot(kind='area', alpha=0.35, figsize=(20,10))
ax.set_title('The Chart Title')
ax.set_xlabel('x-axis name')
ax.set_title('y-axis name') 
plt.show( )

Note:
kind ='area' -- means, the plot is 'area' chart
alpha =0.35 -- means the transparency is 0.35 (35%)
figsize(20,10) -- means, the chart size
plt.title / ax_set_title -- means the title of the chart
plt.xlabel / ax_set_xlabel -- means the title of the X-axis. Usually x axis is the independent variable
plt.ylabel / ax_set_ylabel -- means the title of the Y-axis. Usually Y axis is the target variable
plt.show() -- means show( ) function used to display the chart.







Comments

Popular Posts