Open links in new tab
  1. The matplotlib.pyplot.plot() function is a versatile tool for creating 2D visualizations such as line graphs, scatter plots, and more. It allows customization of line styles, markers, and colors, making it ideal for plotting mathematical functions or datasets.

    Example – Plotting a Quadratic Function:

    import matplotlib.pyplot as plt
    import numpy as np

    # Define the function
    def f(x):
    return x ** 2

    # Create x and y values
    x = np.linspace(-5, 5, 1000)
    y = f(x)

    # Plot the function
    plt.plot(x, y, label='f(x) = x²', color='blue')
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')
    plt.title('Quadratic Function Plot')
    plt.legend()
    plt.grid(True)
    plt.show()
    Copied!

    This code uses NumPy to generate evenly spaced x values and applies the function element-wise. The plot() method then draws the curve with labels and a grid for clarity.

    Plotting Multiple Functions You can plot multiple functions on the same axes by calling plot() multiple times before show():

    def g(x):
    return 5 * np.sin(x)

    x = np.linspace(-5, 5, 1000)
    plt.plot(x, f(x), label='x²', color='blue')
    plt.plot(x, g(x), label='5sin(x)', color='red', linestyle='--')
    plt.title('Multiple Functions')
    plt.legend()
    plt.show()
    Copied!
  1. Matplotlib.pyplot.plot() function in Python

    Jul 15, 2025 · The plot () function allows us to plot data points, customize line styles, markers and colors making it useful for various types of visualizations. In …

  2. People also ask
    Loading
    Unable to load answer
  3. How to Plot a Function in Python with Matplotlib - datagy

    Learn to plot functions using Python, customize plot appearance, and export your plots for sharing with others. This tutorial covers Matplotlib and Seaborn libraries, and shows ho…

    In order to plot a function in Python using Matplotlib, we need to define a range of x and y values that correspond to that function. In order to do this, we need to: 1. Define our function, and 2. Create a range of continuous x-values and map their corresponding y-v…
    See more on datagy.io
  4. Matplotlib Plotting - W3Schools

    Learn how to use the plot() function to draw points, lines and markers in a diagram. See examples of x and y coordinates, shortcut notation and default x-points.

  5. How Can I Plot a Function in Python?

    Learn how to plot a function in Python with easy-to-follow steps and examples. This guide covers popular libraries like Matplotlib to help you visualize mathematical functions effectively.

  6. matplotlib.pyplot.plot — Matplotlib 3.10.8 documentation

    There are various ways to plot multiple sets of data. The most straight forward way is just to call plot multiple times. Example: If x and/or y are 2D arrays, a separate …

  7. How to Plot a Function in Python — codegenes.net

    Jan 16, 2026 · Plotting functions in Python using libraries like matplotlib and numpy is a powerful and flexible way to visualize mathematical relationships. By understanding the fundamental concepts, …

  8. Plotting Functions in Python: A Comprehensive Guide

    Apr 2, 2025 · Python offers several powerful libraries for plotting functions, with matplotlib and numpy being the most commonly used. This blog post will explore how to plot functions in Python, covering …

  9. Graph Plotting in Python | Set 1 - GeeksforGeeks

    Jul 23, 2025 · In this example, the code uses Matplotlib to create a simple line plot. It defines x and y values for data points, plots them using `plt.plot ()`, and labels …

  10. Matplotlib Tutorial – A Complete Guide to Python Plot with Examples

    The goal of this tutorial is to make you understand ‘how plotting with matplotlib works’ and make you comfortable to build full-featured plots with matplotlib.