
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to specify values on Y-axis in Python Matplotlib?
To specify values on Y-axis in Python, we can take the following steps−
- Create x and y data points using numpy.
- To specify the value of axes, create a list of characters.
- Use xticks and yticks method to specify the ticks on the axes with x and y ticks data points respectively.
- Plot the line using x and y, color=red, using plot() method.
- Make x and y margin 0.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([0, 2, 4, 6]) y = np.array([1, 3, 5, 7]) ticks = ['a', 'b', 'c', 'd'] plt.xticks(x, ticks) plt.yticks(y, ticks) plt.plot(x, y, c='green') plt.margins(x=0, y=0) plt.show()
Output
- Related Articles
- How to set X-axis values in Matplotlib Python?
- How to turn on minor ticks only on the y-axis Matplotlib?
- How to display Matplotlib Y-axis range using absolute values rather than offset values?
- Change values on matplotlib imshow() graph axis
- How to plot values with log scales on x and y axis or on a single axis in R?
- How to force Matplotlib to show the values on X-axis as integers?
- How to plot on secondary Y-Axis with Python Plotly?
- How to share secondary Y-axis between subplots in Matplotlib?
- How to exponentially scale the Y axis with matplotlib?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to plot multiple Pandas columns on the Y-axis of a line graph (Matplotlib)?
- How to represent all values of X-axis or Y-axis on the graph in R using ggplot2 package?
- How to force the Y axis to use only integers in Matplotlib?
- Setting Y-axis in Matplotlib using Pandas
- How to plot multiple lines on the same Y-axis in Python Plotly?

Advertisements