Python Encyclopedia for Academics
  • Course Outline
  • Artificial Intelligence
    • Data Science Foundation
      • Python Programming
        • Introduction and Basics
          • Variables
          • Print Function
          • Input From User
          • Data Types
          • Type Conversion
        • Operators
          • Arithmetic Operators
          • Relational Operators
          • Bitwise Operators
          • Logical Operators
          • Assignment Operators
          • Compound Operators
          • Membership Operators
          • Identity Operators
      • Numpy
        • Vectors, Matrix
        • Operations on Matrix
        • Mean, Variance, and Standard Deviation
        • Reshaping Arrays
        • Transpose and Determinant of Matrix
      • Pandas
        • Series and DataFrames
        • Slicing, Rows, and Columns
        • Operations on DataFrames
        • Different wayes to creat DataFrame
        • Read, Write Operations with CSV files
      • Matplotlib
        • Graph Basics
        • Format Strings in Plots
        • Label Parameters, Legend
        • Bar Chart, Pie Chart, Histogram, and Scatter Plot
  • Machine Learning Algorithms
    • Regression Analysis In ML
      • Regression Analysis in Machine Learning
      • Proof of Linear Regression Formulas
      • Simple Linear Regression Implementation
      • Multiple Linear Regression
      • Advertising Dataset Example
      • Bike Sharing Dataset
      • Wine Quality Dataset
      • Auto MPG Dataset
    • Classification Algorithms in ML
      • Proof of Logistic Regression
      • Simplified Mathematical Proof of SVM
      • Iris Dataset
  • Machine Learning Laboratory
    • Lab 1: Titanic Dataset
      • Predicting Survival on the Titanic with Machine Learning
    • Lab 2: Dow Jones Index Dataset
      • Dow Jones Index Predictions Using Machine Learning
    • Lab 3: Diabetes Dataset
      • Numpy
      • Pandas
      • Matplotlib
      • Simple Linear Regression
      • Simple Non-linear Regression
      • Performance Matrix
      • Preprocessing
      • Naive Bayes Classification
      • K-Nearest Neighbors (KNN) Classification
      • Decision Tree & Random Forest
      • SVM Classifier
      • Logistic Regression
      • Artificial Neural Network
      • K means Clustering
    • Lab 4: MAGIC Gamma Telescope Dataset
      • Classification in ML-MAGIC Gamma Telescope Dataset
    • Lab 5: Seoul Bike Sharing Demand Dataset
      • Regression in ML-Seoul Bike Sharing Demand Dataset
    • Lab 6: Medical Cost Personal Datasets
      • Predict Insurance Costs with Linear Regression in Python
    • Lab 6: Predict The S&P 500 Index With Machine Learning And Python
      • Predict The S&P 500 Index With Machine Learning And Python
  • Artificial Neural Networks
    • Biological Inspiration vs. Artificial Neurons
    • Review linear algebra and calculus essentials for ANNs
    • Activation Function
  • Mathematics
    • Pre-Calculus
      • Factorials
      • Roots of Polynomials
      • Complex Numbers
      • Polar Coordinates
      • Graph of a Function
    • Calculus 1
      • Limit of a Function
      • Derivative of Function
      • Critical Points
      • Indefinite Integrals
  • Calculus 2
    • 3D Coordinates and Vectors
    • Vectors and Vector Operations
    • Lines and Planes in Space (3D)
    • Partial Derivatives
    • Optimization Problems (Maxima/Minima) in Multivariable Functions
    • Gradient Vectors
  • Engineering Mathematics
    • Laplace Transform
  • Electrical & electronics Eng
    • Resistor
      • Series Resistors
      • Parallel Resistors
    • Nodal Analysis
      • Example 1
      • Example 2
    • Transient State
      • RC Circuit Equations in the s-Domain
      • RL Circuit Equations in the s-Domain
      • LC Circuit Equations in the s-Domain
      • Series RLC Circuit with DC Source
  • Computer Networking
    • Fundamental
      • IPv4 Addressing
      • Network Diagnostics
  • Cybersecurity
    • Classical Ciphers
      • Caesar Cipher
      • Affine Cipher
      • Atbash Cipher
      • Vigenère Cipher
      • Gronsfeld Cipher
      • Alberti Cipher
      • Hill Cipher
Powered by GitBook
On this page
  • 1. What is a Graph of a Function?
  • 2. Basic Example
  • 3. Key Features of a Graph
  • 4. Python Example: Plotting a Function
  • 5. Try Multiple Graphs Together
  • Keywords
  1. Mathematics
  2. Pre-Calculus

Graph of a Function

Nerd Cafe

1. What is a Graph of a Function?

A graph of a function is the visual representation of all ordered pairs (x, f(x)). It gives us insight into the function’s behavior, such as:

  • Where it increases or decreases

  • Its symmetry

  • Maximum or minimum points

  • Intercepts and asymptotes

A function maps every input x to a unique output f(x). Plotting this for various x-values results in a curve or line.

2. Basic Example

Let’s consider:

f(x)=x2f(x)=x^{2}f(x)=x2

To graph this, we compute several (x, f(x)) values:

x
f(x) = x²

-3

9

-2

4

-1

1

0

0

1

1

2

4

3

9

Plotting these points gives a parabola opening upwards.

3. Key Features of a Graph

When analyzing graphs, observe:

Feature
Description

Domain

All x-values for which f(x) is defined

Range

All possible f(x) values

x-intercepts

Where the graph crosses the x-axis (f(x) = 0)

y-intercept

Where the graph crosses the y-axis (x = 0)

Asymptotes

Lines that the graph approaches but never touches

Symmetry

Even/Odd/None

Increasing/Decreasing Intervals

Where the graph goes up/down

Maximum/Minimum

Peaks and valleys of the graph

4. Python Example: Plotting a Function

Example 1: Plotting 𝑓(𝑥)=x2

Let’s use matplotlib and numpy to graph a function.

import numpy as np
import matplotlib.pyplot as plt

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

# Generate x values
x = np.linspace(-10, 10, 400)
y = f(x)

# Plot
plt.figure(figsize=(8,5))
plt.plot(x, y, label="f(x) = x²", color='blue')
plt.axhline(0, color='black', linewidth=0.5)  # x-axis
plt.axvline(0, color='black', linewidth=0.5)  # y-axis
plt.title("Graph of f(x) = x²")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()

Output:

You can also plot using sympy.

import sympy as sp

# Define the symbolic variable and function
x = sp.symbols('x')
f = x**2

# Plot using sympy
sp.plotting.plot(f, (x, -10, 10),
                 title="Graph of f(x) = x²",
                 xlabel="x", ylabel="f(x)",
                 line_color='blue', legend=True)

Output:

Example 2: 𝑓(𝑥)=sin(x)

Let’s use matplotlib and numpy to graph a function.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-2*np.pi, 2*np.pi, 400)
y = np.sin(x)

plt.figure(figsize=(8,5))
plt.plot(x, y, label="f(x) = sin(x)", color='green')
plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)
plt.title("Graph of f(x) = sin(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()

Output:

You can also plot using sympy.

import sympy as sp

# Define the symbolic variable and function
x = sp.symbols('x')
f = sp.sin(x)

# Plot using sympy
sp.plotting.plot(f, (x, -10, 10),
                 title="Graph of f(x) = sin(x)",
                 xlabel="x", ylabel="f(x)",
                 line_color='blue', legend=True)h

Output:

5. Try Multiple Graphs Together

Let’s use matplotlib and numpy to graph a function.

x = np.linspace(-10, 10, 400)

plt.figure(figsize=(10,6))

# Define functions
plt.plot(x, x, label="f(x) = x")
plt.plot(x, x**2, label="f(x) = x²")
plt.plot(x, x**3, label="f(x) = x³")
plt.plot(x, np.sin(x), label="f(x) = sin(x)")
plt.plot(x[x!=0], 1/x[x!=0], label="f(x) = 1/x")

plt.axhline(0, color='black', linewidth=0.5)
plt.axvline(0, color='black', linewidth=0.5)

plt.title("Multiple Function Graphs")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()

Output:

You can also plot using sympy.

import sympy as sp

# Define symbol
x = sp.symbols('x')

# Define functions
f1 = x
f2 = x**2
f3 = x**3
f4 = sp.sin(x)
f5 = 1/x

# Plot all functions
sp.plot(
    f1, f2, f3, f4, f5,
    (x, -10, 10),
    title="Multiple Function Graphs",
    xlabel="x",
    ylabel="f(x)",
    legend=True,
    show=True
)

Output:

Keywords

symbolic math, sympy, sine function, sin(x), plot sin, symbolic plotting, python math, calculus, symbolic computing, algebra, trigonometry, math visualization, pure sympy, no numpy, no matplotlib, math graph, function plot, symbolic expression, math function, sympy plot, nerd cafe

PreviousPolar CoordinatesNextCalculus 1

Last updated 2 months ago