4.2 KiB
Quadratic Equation Plotter
A Python GUI application for plotting quadratic equations using Tkinter and Matplotlib.
Features
- Plot any quadratic equation in the form: y = ax² + bx + c
- Adjustable X-axis range
- Visualize vertex and roots (when they exist)
- Save plots in multiple formats (PNG, JPEG, PDF, SVG)
- Interactive matplotlib navigation toolbar (zoom, pan, save)
- Clean, user-friendly interface
Requirements
- Python 3.6 or higher
- NumPy
- Matplotlib
Installation
- Install Python dependencies:
pip install -r requirements.txt
Or install manually:
pip install numpy matplotlib
Usage
Run the application:
python quadratic_plotter.py
Interface Components:
-
Coefficients Input:
- Enter values for
a,b, andc - Default: a=1, b=0, c=0 (plots y = x²)
- Enter values for
-
X-axis Range:
- Set the range of x-values to plot
- Default: -10 to 10
-
Buttons:
- Plot Quadratic: Generate the plot with current parameters
- Save Plot: Save the current plot to a file
- Clear Plot: Clear the current plot
-
Plot Area:
- Interactive matplotlib plot with zoom and pan capabilities
- Vertex shown as red dot (for a ≠ 0)
- Roots shown as green dots (when real roots exist)
- Legend showing equation and key points
Example Plots
- Standard Parabola: a=1, b=0, c=0
- Shifted Parabola: a=1, b=-2, c=1
- Downward Parabola: a=-1, b=0, c=4
- Linear Function: a=0, b=2, c=1 (plots a straight line)
Features in Detail
Vertex Calculation
The vertex of the parabola is calculated using:
x_vertex = -b / (2a)
y_vertex = a(x_vertex)² + b(x_vertex) + c
Roots Calculation
Real roots are calculated using the quadratic formula:
x = [-b ± √(b² - 4ac)] / (2a)
Plot Customization
- Blue line: Quadratic curve
- Red dot: Vertex of parabola
- Green dots: Real roots (x-intercepts)
- Grid lines for easy reference
- Axes lines through origin
Error Handling
The application includes error handling for:
- Invalid numeric input
- X-min greater than X-max
- File save errors
- Missing dependencies
License
This project is open source and available for educational and personal use.
Troubleshooting
If you encounter issues:
- Missing dependencies: Ensure all packages are installed
- GUI not showing: Check if Tkinter is installed (usually bundled with Python)
- Plot not updating: Verify all input fields contain valid numbers
- ImportError: "NavigationToolbar2Tk" is not exported: This application includes compatibility code for different matplotlib versions. If you see this error, update matplotlib to version 3.4 or later:
The code will automatically try multiple import locations for backward compatibility.pip install --upgrade matplotlib
Screenshot
Note: Add your own screenshot after running the application
GitHub Repository Setup
This project is already initialized as a Git repository. To push it to a private GitHub repository:
Option 1: Using GitHub CLI (Recommended)
-
Install GitHub CLI if not already installed:
# On Ubuntu/Debian sudo apt install gh # On macOS brew install gh -
Authenticate with GitHub:
gh auth login -
Create a new private repository:
gh repo create quadratic-plotter --private --source=. --remote=origin --push
Option 2: Manual Setup
-
Create a new private repository on GitHub.com:
- Repository name:
quadratic-plotter(or your preferred name) - Select "Private"
- Do NOT initialize with README, .gitignore, or license
- Repository name:
-
Add the remote and push:
git remote add origin https://github.com/YOUR_USERNAME/quadratic-plotter.git git branch -M main git push -u origin main
Option 3: Using SSH
If you prefer SSH authentication:
- Add your SSH key to GitHub
- Use SSH URL:
git remote add origin git@github.com:YOUR_USERNAME/quadratic-plotter.git git branch -M main git push -u origin main
Verification
After pushing, verify your repository:
git log --oneline
git remote -v
git status
