- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to plot 1D data at a given Y-value with PyLab using Matplotlib?
To plot 1D data at a given Y-value with pyplot, we can take the following steps−
- Initialize y value.
- Create x and y data points using numpy. zeros_like helps to return an array of zeros with the same shape and type as a given array and add y-value for y data points.
- Plot x and y with linestyle=dotted, color=red, and linewidth=5.
- 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 y_value = 1 x = np.arange(10) y = np.zeros_like(x) + y_value plt.plot(x, y, ls='dotted', c='red', lw=5) plt.show()
Output
- Related Articles
- How to make a 4D plot with Matplotlib using arbitrary data?
- How to plot single data with two Y-axes (two units) in Matplotlib?
- How to plot a line in Matplotlib with an interval at each data point?
- How to plot an image with non-linear Y-axis with Matplotlib using imshow?
- How to plot a histogram using Matplotlib in Python with a list of data?
- How to print the Y-axis label horizontally in a Matplotlib/Pylab chart?
- Which is the recommended way to plot – matplotlib or pylab?
- How to use different markers for different points in a Pylab scatter plot(Matplotlib)?
- How to extract data from a Matplotlib plot?
- How to plot arbitrary markers on a Pandas data series using Matplotlib?
- Plot data from a .txt file using matplotlib
- How to plot CSV data using Matplotlib and Pandas in Python?
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot data into imshow() with custom colormap in Matplotlib?

Advertisements