Simple plot

3.1. Simple plot#

Let’s start by creating a simple line plot of the equation \(y=3x+5\). We will use numpy to create an array which acts as our x-axis

x = np.linspace(0,10)
y = 3*x + 5

plt.figure(figsize=(6,3))
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Plot')
plt.show()
../_images/1e03403f6d9b2a8821e1c705a318c85bf366d57b6ec3de96b1ae9ac959b09093.png

Let’s break it down

Here’s a breakdown of what each line does:

  1. x = np.linspace(0, 10): This line generates a sequence of evenly spaced numbers between 0 and 10. np.linspace() creates an array of numbers with a specified start and end point.

  2. y = 3*x + 5: This line calculates the values for the y-axis based on the values of x. It uses a simple equation 3*x + 5, which means each y-value is obtained by multiplying the corresponding x-value by 3 and adding 5.

  3. plt.figure(figsize=(6,3)): This line creates a new figure (or plot) with a specified size. The figsize parameter sets the width and height of the figure. In this case, the width is 6 units and the height is 3 units.

  4. plt.plot(x, y): This line plots the x and y values on the figure. It takes the x and y values as input and connects them with a line.

  5. plt.xlabel('X-axis'): This line sets the label for the x-axis of the plot to ‘X-axis’.

  6. plt.ylabel('Y-axis'): This line sets the label for the y-axis of the plot to ‘Y-axis’.

  7. plt.title('Line Plot'): This line sets the title of the plot to ‘Line Plot’.

  8. plt.show(): This line displays the plot on the screen. plt.show() is a function that shows the plot that has been created.