MatplotLib
Greetings! I'm Vishnu Vinay, a Computer Science and Engineering graduate holding a B. Tech degree. Currently immersed in the captivating world of Artificial Intelligence, I am on a quest for knowledge while pursuing a graduate certificate in Artificial Intelligence with Machine Learning. My passion lies in sharing insights and discoveries in the fields of AI, Machine Learning, Artificial General Intelligence, and Robotics through engaging blog posts. Proficient in Python, ML libraries, and algorithms, I find joy in developing and deploying ML models, with a focus on leveraging AWS Sagemaker. Join me on this exciting journey of unraveling the mysteries of AI through the lens of coding, exploration, and the ever-evolving landscape of machine learning. Let's embark on this knowledge-sharing adventure together!
- ) Plotting graphs
/ import the module
import matplotlib.pyplot as plt
/ dummy points as 2 arrays for the x and y points
x = [1, 2, 3]
y = [2, 4, 6]
1.1) Case 1: only shows the points on the graph no connecting them with the line
/ adds the points in the graph but no output
plt.scatter(x, y)
/ acts like a print function in the case of graphs
plt.show()
1.2) Case 2: points are connected by a line
x = [1, 2, 3]
y = [2, 4, 6]
/ connected by a line but points are now invisible
plt.plot(x, y)
plt.show()
1.3) Case 3: combining steps 1.1 and 1.2
x = [1, 2, 3]
y = [2, 4, 6]
plt.scatter(x, y)
plt.plot(x, y)
plt.show()
In this case, we can see the line connecting the points and also the points will be visible on the line.
- Creating 2 different lines
/ Dummy points line 1
x = [1, 2, 3]
y = [2, 4, 6]
/ Dummy points line 2
x2 = [3, 4, 5]
y2 = [2, 4, 6]
plt.scatter(x, y)
plt.plot(x, y)
plt.scatter(x2, y2)
plt.plot(x2, y2)
plt.show()
Note: The points for the x and y axis are automatically assigned. While x and y array values are used to get the (x, y) point which is plotted on the graph.
- Plotting graph with single axis
a = [3, 4, 5] # -> considers it as y points
/ for x - points it takes range from 0 to number of points - 1
plt.plot(a)
plt.show()