- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Can I give a border to a line in Matplotlib plot function?
To give a border to a line in matplotlib plot function, we can call plot() function twice with varying line width.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x and y data points using numpy.
- Plot x and y data points where line width=10 and color=black.
- Again plot x and y points where line width=8 and color=red.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 100) y = np.sin(x) plt.plot(x, y, c='black', lw=10) plt.plot(x, y, c='red', lw=8) plt.show()
Output
- Related Articles
- How can I plot a confusion matrix in matplotlib?
- How to animate a line plot in Matplotlib?
- How can I place a table on a plot in Matplotlib?
- How can I plot a single point in Matplotlib Python?
- Add a custom border to certain cells in a Matplotlib / Seaborn plot
- How do I plot a step function with Matplotlib in Python?
- How to plot a 3D continuous line in Matplotlib?
- How to plot a gradient color line in matplotlib?
- How to plot a smooth line with matplotlib?
- How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?
- How can I plot hysteresis threshold in Matplotlib?
- How to plot a multivariate function in Python Matplotlib?
- How can I make a simple 3D line with Matplotlib?
- How can I draw a scatter trend line using Matplotlib?
- How can I create a stacked line graph with matplotlib?

Advertisements