What is pyplot and Line plots in Matplotlib – Data Visualization using Python

matplotlib.pyplot is a collection of command style functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.

In this article, we will see how to use pyplot to draw line graph. Here is most basic plot

https://gist.github.com/conquistadorjd/820c117b75d52514b2e58008be07a6eb#file-pyplot-01-py

Here is the output

You can add customization to line as below:

https://gist.github.com/conquistadorjd/820c117b75d52514b2e58008be07a6eb#file-pyplot-03-py

Line has various properties and these can be found here.

character description
'-' solid line style
'--' dashed line style
'-.' dash-dot line style
':' dotted line style
'.' point marker
',' pixel marker
'o' circle marker
'v' triangle_down marker
'^' triangle_up marker
'<' triangle_left marker
'>' triangle_right marker
'1' tri_down marker
'2' tri_up marker
'3' tri_left marker
'4' tri_right marker
's' square marker
'p' pentagon marker
'*' star marker
'h' hexagon1 marker
'H' hexagon2 marker
'+' plus marker
'x' x marker
'D' diamond marker
'd' thin_diamond marker
'|' vline marker
'_' hline marker

Color codes are as below

character color
‘b’ blue
‘g’ green
‘r’ red
‘c’ cyan
‘m’ magenta
‘y’ yellow
‘k’ black
‘w’ white
CategoriesUncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *