Skip to main content

A package for creating interactive plots.

Project description

My Interactive Plots

Downloads

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.5.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.5-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: my_interactive_plots-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 98677c5d2fe4a4f81b9fcb955ebec1d74a0375a86dabe24de07fc0d0c96080d5
MD5 40fdf088280f30cd2968c843f6854bd9
BLAKE2b-256 fac9a3950335c03ddd06cd1d9228ed72e47aca22e36a652e60f99349a667db75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for my_interactive_plots-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 008affdf172fc16f5c8bdb6467436fee48e00f3bff979af6be16238741291e8c
MD5 f7ad780d62415d85a29e77985713bd80
BLAKE2b-256 dcedf3f82c01af4611a6a60d00ed04e3101fa2247ccaa4888fb99f8a3cac0e0e

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