Data Visualisation using Matplotlib for beginners.

Photo by Luke Chesser on Unsplash
  • Line plots
  • Scatter Plots
  • Bar Graphs
  • Pie Charts
  • Histograms

Line Plots

1.Get the data

x=np.arange(10)
y1= x**2
y2=2*x+34
print(x)
print(y1)
print(y2)
Output---------[0 1 2 3 4 5 6 7 8 9]
[ 0 1 4 9 16 25 36 49 64 81]
[34 36 38 40 42 44 46 48 50 52]

2. Plot Simple curves

plt.plot(x,y1)
plt.show
You will get this graph as output. Similarly, you can plot for other functions as well.
Credits: imgflip.com

3. Use themes to make the plot look more attractive

themes=plt.style.available
print(themes)
plt.style.use(“seaborn-paper”)
plt.plot(x,y1)
plt.show
Using the seaborn paper theme we got the gray colour border and curve, and grd on the graph.

4. Change the color of curve

plt.style.use(“seaborn-paper”)
plt.plot(x,y1, color=”red”)
plt.plot(x,y2, color=”green”)
plt.show
We can plot different curves on same plot using different colors

5. Give titles

  • plt.xlabel(“ ”): to put a label on x axis.
  • plt.ylabel(“ ”): to put a label on y axis.
  • plt.title(“ ”): to gve a title to the plot.
plt.xlabel(“Time”)
plt.ylabel(“Speed”)
plt.title(“Speed v/s Time Curve”)
We got the label for x and y axis along with the title for curve.

6. Give labels to different curves an plot legend

plt.style.use(“seaborn-paper”)
plt.plot(x,y1, color=”red”, label=”A”)
plt.plot(x,y2, color=”green”, label=”B”)
plt.legend()
plt.xlabel(“Tme”)
plt.ylabel(“Speed”)
plt.title(“Speed v/s Time Curve”)
plt.show

7. Change style of curve

plt.plot(x,y1, color=”red”, label=”A”, linestyle=”dashed”)

8. Putting a marker

plt.plot(x,y1, color=”red”, label=”A”, linestyle=”dashed”, marker=”o”)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a Budget News-Based Algorithmic Trader? Well then You Need Hard-To-Find Data

The Power and Pitfalls of Inferencing

Deep Stacking Network (DSN)

Starting Out With Data Science (Episode I): what you should learn!

More 25–34-year-olds are living with their parents in cities in Ontario… but not in Alberta and…

Finding the next Billboard #1 — Spotify API Exploratory Analysis

Are We Using Machine Learning?

A Holistic Framework for Managing Data Analytics Projects

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shatakshi Singh

Shatakshi Singh

More from Medium

Data Manipulation with df_product.csv Dataset

Introduction :

Exploratory Data Analysis

Performing Analysis of Meteorological Data