Unit_I_1_1
Unit_I_1_1
What is Matplotlib
• It is an open-source drawing library which supports rich
drawing types.
• It is used to draw 2D and 3D graphics.
Why
• You can understand your data easily by visualization it
with the help of matplotlib.
• You can generate plots, histograms, bar charts and
many other charts with just a few lines of code.
Types of plots
Import MATPLOTLIB
MATPLOTLIB graph functions
MATPLOTLIB graph functions
Graph Functions
Graph Functions
Graph Functions
Formatting Graphs
Line graph
• Line charts are typically used to visualize data points over a
continuous interval or time period. They are particularly useful for
showing trends and patterns in data.
Two things to note from this plot:
To plot multiple curves simply call plt.plot with as many x–y list pairs as needed:
Multiple Line graph
more plots may be added by repeatedly calling plt.plot.
Also, adding an legend is rather simple:
Adjusting axis ranges can be done by calling plt.xlim and plt.ylim with the lower and higher
limits for the respective axes.
The style strings, one per x–y pair, specify color and shape: ‘rx’ stands for red crosses, and ‘b-.’
stands for blue dash-point line.
Save the plot
• plt.savefig('my_plot.png')
Assignment using line plot
• Draw the line plot for sepal length, sepal width, petal
length and petal width individually.
• Plot then plot in one plot. (assign the different color for
different plot, add legend)
• Provide the axis name, limit, and save the plot.
• Also change the font of the plot’s axis.
• Change the color of the grid, change the grid to major
and linewidth to 1.5.
• Plot a subplot for each individual features in iris dataset.
Bar Chart
Bar Charts
Types of Bar charts
Examples
Side-By-Side Bars Chart
Example
Difference of Bar and Histogram
chart
Difference of Bar and Histogram
chart
Creating a bar plot
The syntax of the bar() function to be used with the axes is as follows:-
plt.bar(x, height, width, bottom, align)
x_positions = [0, 1, 2]
heights = [6, 12, 9]
plt.bar(x_positions, heights)
plt.show()
Creating a bar plot
import numpy as np
import matplotlib.pyplot as plt
Scatter plot is a plot that display the relationship correlation between two
numerical variables.