181 lines
4.2 KiB
Markdown
181 lines
4.2 KiB
Markdown
# 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
|
|
|
|
1. Install Python dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
Or install manually:
|
|
|
|
```bash
|
|
pip install numpy matplotlib
|
|
```
|
|
|
|
## Usage
|
|
|
|
Run the application:
|
|
|
|
```bash
|
|
python quadratic_plotter.py
|
|
```
|
|
|
|
### Interface Components:
|
|
|
|
1. **Coefficients Input**:
|
|
- Enter values for `a`, `b`, and `c`
|
|
- Default: a=1, b=0, c=0 (plots y = x²)
|
|
|
|
2. **X-axis Range**:
|
|
- Set the range of x-values to plot
|
|
- Default: -10 to 10
|
|
|
|
3. **Buttons**:
|
|
- **Plot Quadratic**: Generate the plot with current parameters
|
|
- **Save Plot**: Save the current plot to a file
|
|
- **Clear Plot**: Clear the current plot
|
|
|
|
4. **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
|
|
|
|
1. **Standard Parabola**: a=1, b=0, c=0
|
|
2. **Shifted Parabola**: a=1, b=-2, c=1
|
|
3. **Downward Parabola**: a=-1, b=0, c=4
|
|
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:
|
|
|
|
1. **Missing dependencies**: Ensure all packages are installed
|
|
2. **GUI not showing**: Check if Tkinter is installed (usually bundled with Python)
|
|
3. **Plot not updating**: Verify all input fields contain valid numbers
|
|
4. **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:
|
|
```bash
|
|
pip install --upgrade matplotlib
|
|
```
|
|
The code will automatically try multiple import locations for backward compatibility.
|
|
|
|
## 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)
|
|
|
|
1. Install GitHub CLI if not already installed:
|
|
```bash
|
|
# On Ubuntu/Debian
|
|
sudo apt install gh
|
|
|
|
# On macOS
|
|
brew install gh
|
|
```
|
|
|
|
2. Authenticate with GitHub:
|
|
```bash
|
|
gh auth login
|
|
```
|
|
|
|
3. Create a new private repository:
|
|
```bash
|
|
gh repo create quadratic-plotter --private --source=. --remote=origin --push
|
|
```
|
|
|
|
### Option 2: Manual Setup
|
|
|
|
1. Create a new private repository on [GitHub.com](https://github.com/new):
|
|
- Repository name: `quadratic-plotter` (or your preferred name)
|
|
- Select "Private"
|
|
- Do NOT initialize with README, .gitignore, or license
|
|
|
|
2. Add the remote and push:
|
|
```bash
|
|
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:
|
|
|
|
1. Add your SSH key to GitHub
|
|
2. Use SSH URL:
|
|
```bash
|
|
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:
|
|
```bash
|
|
git log --oneline
|
|
git remote -v
|
|
git status
|
|
``` |