0% found this document useful (0 votes)
5 views4 pages

Matplotlib Graphing Examples

The document contains Python code snippets that utilize Matplotlib and NumPy to create various types of plots. It includes a simple line graph of y = x, a comparison of y = x and y = x², a scatter plot of random numbers, and a graph of y = sin(x). Each plot is labeled and displayed with appropriate titles and legends.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Matplotlib Graphing Examples

The document contains Python code snippets that utilize Matplotlib and NumPy to create various types of plots. It includes a simple line graph of y = x, a comparison of y = x and y = x², a scatter plot of random numbers, and a graph of y = sin(x). Each plot is labeled and displayed with appropriate titles and legends.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

In [1]: import matplotlib.

pyplot as plt
import numpy as np

# Data
x = [Link](0, 10, 100) # 100 points between 0 and 10
y = x

# Plot
[Link](x, y, label="y = x")
[Link]("x")
[Link]("y")
[Link]("Simple Line Graph of y = x")
[Link]()
[Link]()

In [2]: import [Link] as plt


import numpy as np

# Data
x = [Link](0, 10, 100)
y1 = x
y2 = x**2

# Plot both lines


[Link](x, y1, label="y = x", color="blue")
[Link](x, y2, label="y = x²", color="red")
[Link]("x")
[Link]("y")
[Link]("Two Lines on Same Axes")
[Link]()
[Link]()

In [3]: import [Link] as plt


import numpy as np

# Random data
x = [Link](50) # 50 random numbers between 0 and 1
y = [Link](50)

# Scatter plot
[Link](x, y, color="green", marker="o")
[Link]("x")
[Link]("y")
[Link]("Scatter Plot of Random Numbers")
[Link]()
In [4]: import [Link] as plt
import numpy as np

# Data
x = [Link](0, 2*[Link], 100)
y = [Link](x)

# Plot
[Link](x, y, label="y = sin(x)", color="purple")
[Link]("x")
[Link]("y")
[Link]("Graph of y = sin(x)")
[Link]()
[Link]()

You might also like