Data Visualization
Data Visualization
• test=sales.groupby(by=["Region"])
• Here, the main dataset name is sales
that have a column named “Region.”
We can utilize the get_group function
to grab specific groups, as follows:
• test.get_group("East")
• test.get_group("West")
Understanding Pandas Groupby for Data
Aggregation
• plt.show()
• Adding Title
• The title() method in matplotlib module is used to specify
the title of the visualization depicted and displays the title
using various attributes.
• import matplotlib.pyplot as plt
• plt.show()
#We can also change the appearance of
the title by using the parameters of this
• import matplotlib.pyplot as plt
• # initializing the data
• x = [10, 20, 30, 40]
• y = [20, 25, 35, 55]
• plt.show()
• Adding X Label and Y Label
• In layman’s terms, the X label and the Y label are the titles
given to X-axis and Y-axis respectively. These can be added
to the graph by using the xlabel() and ylabel() methods.
• import matplotlib.pyplot as plt
• # initializing the data
• x = [10, 20, 30, 40]
• y = [20, 25, 35, 55]
• # plotting the data
• plt.plot(x, y)
• # Adding title to the plot
• plt.title("Linear graph", fontsize=25, color="green")
• # Adding label on the y-axis
• plt.ylabel('Y-Axis')
• # Adding label on the x-axis
• plt.xlabel('X-Axis')
• plt.show()
• Setting Limits and Tick labels
• You might have seen that Matplotlib automatically sets the values and the
markers(points) of the X and Y axis, however, it is possible to set the limit
and markers manually. xlim() and ylim() functions are used to set the limits
of the X-axis and Y-axis respectively. Similarly, xticks() and yticks() functions
are used to set tick labels.
• import matplotlib.pyplot as plt
• # initializing the data
• x = [10, 20, 30, 40]
• y = [20, 25, 35, 55]
• # plotting the data
• plt.plot(x, y)
• # Adding title to the plot
• plt.title("Linear graph", fontsize=25, color="green")
• # Adding label on the y-axis
• plt.ylabel('Y-Axis')
• # Adding label on the x-axis
• plt.xlabel('X-Axis')
• # Setting the limit of y-axis
• plt.ylim(0, 80)
• # setting the labels of x-axis
• plt.xticks(x, labels=["one", "two", "three", "four"])
• plt.show()
• Adding Legends
• A legend is an area describing the elements of the graph. In simple
terms, it reflects the data displayed in the graph’s Y-axis. It
generally appears as the box containing a small sample of each
color on the graph and a small description of what this data
means.
• The attribute bbox_to_anchor=(x, y) of legend() function is used to
specify the coordinates of the legend, and the attribute ncol
represents the number of columns that the legend has. Its default
value is 1.
import matplotlib.pyplot as plt
# initializing the data
x = [10, 20, 30, 40]
y = [20, 25, 35, 55]
# plotting the data
plt.plot(x, y)
# Adding title to the plot
plt.title("Linear graph", fontsize=25, color="green")
# Adding label on the y-axis
plt.ylabel('Y-Axis')
# Adding label on the x-axis
plt.xlabel('X-Axis')
# Setting the limit of y-axis
plt.ylim(0, 80)
# setting the labels of x-axis
plt.xticks(x, labels=["one", "two", "three", "four"])
# Adding legends
plt.legend(["GFG"])
plt.show()
• Figure class
• Consider the figure class as the overall window or page on which
everything is drawn. It is a top-level container that contains one or
more axes. A figure can be created using the figure() method.
• # Python program to show pyplot module
• import matplotlib.pyplot as plt
• from matplotlib.figure import Figure
• # initializing the data
• x = [10, 20, 30, 40] ,y = [20, 25, 35, 55]
• # Creating a new figure with width = 7 inches
• # and height = 5 inches with face color as
• # green, edgecolor as red and the line width of the edge as 7
• fig = plt.figure(figsize =(7, 5), facecolor='g',
• edgecolor='b', linewidth=7)
• # Creating a new axes for the figure
• ax = fig.add_axes([1, 1, 1, 1])
• # Adding the data to be plotted
• ax.plot(x, y)
• # Adding title to the plot
• plt.title("Linear graph", fontsize=25, color="yellow")
• # Adding label on the y-axis
• plt.ylabel('Y-Axis’) # Adding label on the x-axis
• plt.xlabel('X-Axis')
• # Setting the limit of y-axis plt.ylim(0, 80)
• # setting the labels of x-axis
• plt.xticks(x, labels=["one", "two", "three", "four"])
• # Adding legends
• plt.legend(["GFG"])
• plt.show()
Function Overloading
Finding Gross Pay
• Three are three types of employees in Indian railways.
They are regular, daily wages and consolidated
employees. Gross Pay for the employees are
calculated as follows:
• regular employees - basic + hra + % of DA * basic
1. Function overloading
2. Operator overloading
3. Dynamic binding
Overloading
• Overloading – A name having two or more
distinct meanings
linkage.
Signature of a Function
• A function’s argument list (i.e., number and type of
argument) is known as the function’s signature.
• Functions with Same signature - Two
functions with same number and types of
arguments in same order
• variable names doesn’t matter. For
instance, following two functions have
same signature.
void squar (int a, float b); //function 1
void squar (int x, float y);
37
Following code fragment overloads a
function name prnsqr( ).
38 38
void prnsqr (int i)
{
cout<<“Integer”<<i<<“’s square is”<<i*i<<“\n”;
}
void prnsqr (char c);
{
cout <<“No Square for characters”<<“\n”;
}
void prnsqr (float f)
{
cout<<“float”<<f <<“’s square is”<<f *f<<“\n”;
}
void prnsqr (double d)
{
cout <<“Double float”<<d<<“’s square is”<<d*d<<“\n’;
39 39
Where does Python belong to?
class Employee:
def display(self):
print("Hello my name is Rahul")
emp_obj1 = Employee()
emp_obj1.display()
emp_obj2 = Employee()
emp_obj2.display()