- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
- Python 3 Advanced Tutorial
- Python 3 - Classes/Objects
- Python 3 - Reg Expressions
- Python 3 - CGI Programming
- Python 3 - Database Access
- Python 3 - Networking
- Python 3 - Sending Email
- Python 3 - Multithreading
- Python 3 - XML Processing
- Python 3 - GUI Programming
- Python 3 - Further Extensions
How to plot two dotted lines and set marker using Matplotlib?
In this program, we will plot two lines using the matplot library. Before starting to code, we need to first import the matplotlib library using the following command −
Import matplotlib.pyplot as plt
Pyplot is a collection of command style functions that make matplotlib work like MATLAB.
Step 1: Import matplotlib.pyplot Step 2: Define line1 and line2 points. Step 3: Plot the lines using the plot() function in pyplot. Step 4: Define the title, X-axis, Y-axis. Step 5: Display the plots using the show() function.
import matplotlib.pyplot as plt line1_x = [10,20,30] line1_y = [20,40,10] line2_x = [10,20,30] line2_y= [40,10,30] plt.xlabel('X AXIS') plt.ylabel('Y AXIS') plt.plot(line1_x ,line1_y , color='blue', linewidth = 3, label = 'line1-dotted',linestyle='dotted') plt.plot(line2_x ,line2_y, color='red', linewidth = 5, label = 'line2-dashed', linestyle='dotted') plt.title("PLOTTING DOTTED LINES") plt.legend() plt.show()
The variables line1_x, line_y and line2_x, line2_y are the coordinates of our lines. The linewidth parameter in the plot function is basically the width/thickness of the line we are plotting. The plt.legend() function in the program is used to place legends like x-axis, y-axis names on the graph.
- Related Articles
- How to create dotted vertical lines in a plot using ggplot2 in R?
- How to set legend marker size and alpha in Matplotlib?
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to plot overlapping lines in Matplotlib?
- How to remove lines in a Matplotlib plot?
- How to plot scatter points with increasing size of marker in Matplotlib?
- How to use a custom png image marker in a plot (Matplotlib)?
- Best way to plot an angle between two lines in Matplotlib
- How to plot the lines first and points last in Matplotlib?
- How to plot two histograms side by side using Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?
- Matplotlib – How to set xticks and yticks with imshow plot?
- How to name different lines in the same plot of Matplotlib?
- Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?