Skip to main content

A package for creating interactive plots.

Project description

My Interactive Plots

PyPI version License: MIT Build Status

A Python package for creating interactive plots using Plotly. Supports various plot types and includes a Command-Line Interface (CLI) for ease of use.

Table of Contents

Installation

Ensure you have Python 3.6+ installed.

Using pip

You can install the package directly from PyPI:

pip install my_interactive_plots

From Source

Clone the repository and install in editable mode:

git clone https://github.com/sdr34/my_interactive_plots.git
cd my_interactive_plots
pip install -e .

Features

  • Interactive Plots: Create scatter, line, histogram, and box plots using Plotly.
  • Command-Line Interface (CLI): Generate plots directly from the terminal.
  • Configurable Settings: Customize plot parameters via configuration files.
  • Logging: Track operations and debug effectively.
  • Comprehensive Testing: Ensure reliability with unit tests.
  • Continuous Integration: Automated testing with GitHub Actions.

Usage

Python API

Use the package within your Python scripts to generate interactive plots.

from my_interactive_plots import create_plot

def main():
    data_path = 'data/iris.csv'  # Path to your CSV data file
    plot_type = 'scatter'        # Choose from 'scatter', 'line', 'histogram', 'box'
    
    fig = create_plot(data_path, plot_type=plot_type)
    fig.show()

if __name__ == "__main__":
    main()

Command-Line Interface (CLI)

After installation, you can use the myplot command in your terminal to create plots.

Examples

Create a scatter plot:

myplot data/iris.csv --plot-type scatter

Create a line plot:

myplot data/iris.csv --plot-type line

Create a histogram:

myplot data/iris.csv --plot-type histogram

Create a box plot:

myplot data/iris.csv --plot-type box

Options

  • DATA_SOURCE: Path to the CSV data file.
  • --plot-type: Type of plot to create (scatter, line, histogram, box). Default is scatter.

Supported Plot Types

  • Scatter Plot: Visualize relationships between two variables.
  • Line Plot: Show trends over time or continuous data.
  • Histogram: Display the distribution of a single variable.
  • Box Plot: Summarize distributions and identify outliers.

Configuration

Plot settings are defined in config.py. You can customize the plot by modifying the configuration.

# my_interactive_plots/config.py

class Config:
    """
    Configuration settings for plots.
    """
    x_column = 'sepal_width'
    y_column = 'sepal_length'
    title = 'Sepal Width vs Sepal Length'

Customizing Plot Settings

To change the columns used for the axes or the plot title, edit the Config class in config.py:

class Config:
    x_column = 'petal_width'    # Changed from 'sepal_width'
    y_column = 'petal_length'   # Changed from 'sepal_length'
    title = 'Petal Width vs Petal Length'  # Updated title

After making changes, rerun your script or CLI command to see the updated plot.

Logging

Logging is set up to track the package's operations. Logs are output to the console, providing insights into the package's behavior and aiding in debugging.

Customizing Logging

The logging configuration can be adjusted in utils.py:

# my_interactive_plots/utils.py

import logging

def setup_logging():
    """
    Configures the logging for the package.
    """
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    )

Testing

The project includes unit tests to ensure functionality.

Running Tests

To run the tests, use:

python -m unittest discover tests

Ensure that you have the necessary test data (data/iris.csv) in place before running tests.

Test Coverage

The tests cover:

  • Creation of different plot types.
  • Handling of invalid plot types.
  • CLI functionality.

Continuous Integration

The project uses GitHub Actions for Continuous Integration (CI). Tests are automatically run on each push and pull request to the main branch.

GitHub Actions Workflow

The workflow is defined in .github/workflows/python-app.yml. It sets up Python, installs dependencies, and runs tests.

# .github/workflows/python-app.yml

name: Python package

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.8'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e .
        pip install pytest click

    - name: Run tests
      run: |
        pytest

Viewing CI Results

Check the "Actions" tab in your GitHub repository to view the status of CI runs.

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the Repository: Click the "Fork" button on the repository page.

  2. Clone Your Fork:

git clone https://github.com/sdr34/my_interactive_plots.git
cd my_interactive_plots
  1. Create a New Branch:
git checkout -b feature/your-feature-name
  1. Make Your Changes: Implement your feature or bugfix.
  2. Commit Your Changes:
git commit -m "Add feature: your feature description"
  1. Push to Your Fork:
git push origin feature/your-feature-name
  1. Open a Pull Request: Navigate to the original repository and open a pull request from your fork.

Coding Standards

  • Follow PEP 8 guidelines.
  • Write clear and concise commit messages.
  • Ensure all tests pass before submitting a pull request.

License

his project is licensed under the MIT License. See the LICENSE file for details.

Additional Notes

  • Data Directory: Ensure that the data/iris.csv file exists in the data directory. You can add your own datasets as needed.
  • Virtual Environment: It's recommended to use a virtual environment to manage dependencies. Create and activate a virtual environment before installing the package.

Creating a Virtual Environment

python -m venv venv

Activate the virtual environment:

  • On Windows:
venv\Scripts\activate
  • On macOS/Linux:
source venv/bin/activate

Installing Dependencies

pip install -e .

Deactivating the Virtual Environment

After you're done, deactivate the virtual environment:

deactivate

Troubleshooting

  • FileNotFoundError: Ensure that the data/iris.csv file exists and the path is correct.
  • Module Not Found Errors: Make sure the package is installed correctly in your environment.
  • Plot Not Displaying: Check if you have a default web browser set up, as Plotly opens plots in the browser.

For further assistance, feel free to open an issue in the repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

my_interactive_plots-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

my_interactive_plots-0.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file my_interactive_plots-0.1.1.tar.gz.

File metadata

  • Download URL: my_interactive_plots-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for my_interactive_plots-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f1e82eaa50fded88899ff619cbfa0412abfff269bc3b8b0c7c48ae3404c5df83
MD5 8f3c0146dc170d33682fd737812a60e7
BLAKE2b-256 5a23061b6ada54b4b2e4571e46c772b14bc5ad36bcf31d7bbf8535503e5df53a

See more details on using hashes here.

File details

Details for the file my_interactive_plots-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for my_interactive_plots-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f3733819debcfc58a6a476437ec79ffbcb5486cfb294f5f5400a5b9aa3f7b72
MD5 8b86a00ec2875da5a89089f78c3b4225
BLAKE2b-256 88d9d59dfdbde617c490782764743cf74617d257fa97a59bd67f2ad585b338de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page