Graph in python is very interesting . You have to import library | matplotlib.pyplot |

Plotting is a graph include some pre built function . These are follows- plot(), title(), lable(), show().

Plot function help you in plotting of function

Title function is used in giving the title of that graph.

Label function is used in labeling graph.

Show function is used in showing your graph.

Syntax for making simple graph

import matplotlib.pyplot as pt
x=[1,3,4]
y=[2,4,3]
pt.plot(x,y)
x=[1,6,0,1,1,9,7,0]
y=[1,2,3,4,5,6,7,8]
pt.plot(x,y,label="x,y")
pt.plot(y,x,label="y,x")
pt.xlabel("time")
pt.ylabel("Space")
pt.title("Not A demo Graph")
pt.legend()
pt.show()

Output of above program is –

Graph with marker – The syntax are same but it had little addup in plot() function .If you has added below syntax

your Graph with marker is done for you .

x=[1,6,0,1,1,9,7,0]
y=[1,2,3,4,5,6,7,8]
pt.plot(x,y, label = "x y",color='green', linestyle='dashed', linewidth = 3,
marker='X', markerfacecolor='blue', markersize=12)
pt.plot(y,x, label = "y x",color='yellow', linestyle='dashed', linewidth = 3,
marker='X', markerfacecolor='blue', markersize=12)
pt.xlabel("time")
pt.ylabel("Space")
pt.title("Not a Demo Graph")
pt.legend()
pt.show()

Output of above program-

**Bar graph**

Syntax of plotting bar graph

import matplotlib.pyplot as plt
x=[1,6,0,1,1,9,7,0]
y=[1,2,3,4,5,6,7,8]
plt.bar(x,y,label="xy")
plt.bar(y,x,label="yx")
plt.xlabel("time")
plt.ylabel("Space")
plt.title("Demo Two Graphs")
plt.legend()
plt.show()

Output of given program is given below

In every graph you can change Color, Width of graph / Width of bar

These are some useful syntax which help in using syntax of graph.

For more post on Python follow our blog.

### Like this:

Like Loading...

*Related*

What for ‘pt.legend()’ is used?

Here pt.legend() is used for scaling the graph . Just run your code with pt.legend () and with out pt.legend() you will see the scaling difference there.