How To Plot In Python

Python is a widely used programming language for a variety of tasks, including data analysis and visualization.

Plotting data in Python is essential for creating visualizations that make complex data more accessible. In this tutorial, we’ll go through the steps of how to plot in Python.

Step 1: Install Matplotlib

Matplotlib is a library in Python that enables you to create high-quality plots and visualizations. To install it, use the following command:

Step 2: Import Matplotlib

After installing Matplotlib, the next step is to import it in your Python code. Use the following code to import Matplotlib:

Step 3: Prepare the Data

To prepare the data for plotting, you need to create two lists of equal length representing the x and y-coordinates of the points you want to plot. For example:

Step 4: Create a Figure and Axes

The next step is to create a figure and axes to hold the plot. Use the following code to create a figure and axes:

Step 5: Plot the Data

To plot the data, use the following code:

This will plot the data as a line chart. If you want to plot a scatter chart, use the following code:

Step 6: Customize the Plot

You can customize the plot by adding a title, labels to the x and y-axes, and changing the style of the plot. Use the following code to customize the plot:

Other properties you can customize include the color and type of the plot, the size of markers for scatter plots, and the size of the plot itself.

Step 7: Display the Plot

Finally, use the following code to display the plot:

This will open a window with the plot you created.


Plotting data in Python is easy with the help of Matplotlib. By following the steps outlined in this tutorial, you can create high-quality visualizations of your data.

Full code: