w3resource

Matplotlib Basic: Draw a line with suitable label in the x axis, y axis and a title

Matplotlib Basic: Exercise-1 with Solution

Write a Python program to draw a line with suitable label in the x axis, y axis and a title.

Sample Solution:

Python Code:

import matplotlib.pyplot as plt
X = range(1, 50)
Y = [value * 3 for value in X]
print("Values of X:")
print(*range(1,50)) 
print("Values of Y (thrice of X):")
print(Y)
# Plot lines and/or markers to the Axes.
plt.plot(X, Y)
# Set the x axis label of the current axis.
plt.xlabel('x - axis')
# Set the y axis label of the current axis.
plt.ylabel('y - axis')
# Set a title 
plt.title('Draw a line.')
# Display the figure.
plt.show()

Sample Output:

Matplotlib Basic: Draw a line with suitable label in the x axis, y axis and a title

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Matplotlib Exercises
Next: Write a Python program to draw a line using given axis values with suitable label in the x axis , y axis and a title.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/graphics/matplotlib/basic/matplotlib-basic-exercise-1.php