Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
alceal authored Aug 29, 2024
2 parents c52b692 + 1fb44cf commit 251c12f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 186 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Rust

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

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
# - name: Run tests
# run: cargo test --verbose
- name: Format
run: cargo fmt
- name: Clippy
run: cargo clippy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ target/
notebook

**/main*.rs
.markdownlint.json
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
# Plotlars

<p align="center">
<a href="https://crates.io/crates/plotlars"><img alt="Crates.io" src="https://img.shields.io/crates/v/plotlars.svg"></a>
<a href="https://docs.rs/plotlars"><img alt="docs.rs" src="https://img.shields.io/docsrs/plotlars"></a>
<a href="https://github.com/your-repo/plotlars/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
<a href="https://crates.io/crates/plotlars">
<img alt="Crates.io" src="https://img.shields.io/crates/v/plotlars.svg"></a>
<a href="https://docs.rs/plotlars">
<img alt="docs.rs" src="https://img.shields.io/docsrs/plotlars">
</a>
<a href="https://github.com/your-repo/plotlars/blob/main/LICENSE">
<img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg">
</a>
</p>


Plotlars is a versatile Rust library that acts as a wrapper around the Plotly crate, bridging the gap between the powerful Polars data analysis library and Plotly. It simplifies the process of creating visualizations from data frames, allowing developers to focus on data insights rather than the intricacies of plot creation.
Plotlars is a versatile Rust library that acts as a wrapper around the Plotly
crate, bridging the gap between the powerful Polars data analysis library and
Plotly. It simplifies the process of creating visualizations from data frames,
allowing developers to focus on data insights rather than the intricacies of
plot creation.

## Motivation

The creation of Plotlars was driven by the need to simplify the process of creating complex plots in Rust, particularly when working with the powerful Polars data manipulation library. Generating visualizations often requires extensive boilerplate code and deep knowledge of both the plotting library (Plotly) and the data structure. This complexity can be a significant hurdle, especially for users who need to focus on analyzing and interpreting data rather than wrestling with intricate plotting logic.

To illustrate this, consider the following example where a scatter plot is created without Plotlars:
The creation of Plotlars was driven by the need to simplify the process of
creating complex plots in Rust, particularly when working with the powerful
Polars data manipulation library. Generating visualizations often requires
extensive boilerplate code and deep knowledge of both the plotting library
(Plotly) and the data structure. This complexity can be a significant hurdle,
especially for users who need to focus on analyzing and interpreting data rather
than wrestling with intricate plotting logic.

**Without Plotlars**
To illustrate this, consider the following example where a scatter plot is
created **without Plotlars**:

```rust
use plotly::{
Expand Down Expand Up @@ -92,11 +105,11 @@ fn main() {
}
```

In this example, creating a scatter plot involves writing substantial code to manually handle the data and configure the plot, including grouping the data by category and setting up the plot layout.

**With Plotlars**
In this example, creating a scatter plot involves writing substantial code to
manually handle the data and configure the plot, including grouping the data by
category and setting up the plot layout.

Now, compare that to the same plot created using Plotlars:
Now, compare that to the same plot created **using Plotlars**:

```rust
use plotlars::{
Expand Down Expand Up @@ -142,7 +155,11 @@ This is the output:

![Plot example](https://imgur.com/PkQ9fsc.png)

With Plotlars, the same scatter plot is created with significantly less code. The library abstracts away the complexities of dealing with individual plot components and allows the user to specify high-level plot characteristics. This streamlined approach not only saves time but also reduces the potential for errors and makes the code more readable and maintainable.
With Plotlars, the same scatter plot is created with significantly less code.
The library abstracts away the complexities of dealing with individual plot
components and allows the user to specify high-level plot characteristics. This
streamlined approach not only saves time but also reduces the potential for
errors and makes the code more readable and maintainable.

## Installation

Expand All @@ -152,8 +169,10 @@ cargo add plotlars

## Features

- Seamless Integration with Polars: Leverage the power of Polars for efficient data manipulation and analysis.
- Support for Multiple Plot Types: Easily create bar, line, scatter, and other plot types.
- Seamless Integration with Polars: Leverage the power of Polars for efficient
data manipulation and analysis.
- Support for Multiple Plot Types: Easily create bar, line, scatter, and other
plot types.
- Customization: Modify plot appearance with an intuitive API.

## License
Expand All @@ -162,6 +181,9 @@ This project is licensed under the MIT License. See the LICENSE.txt file for det

## Acknowledgements

- [Polars](https://github.com/pola-rs/polars): For providing a fast and efficient data manipulation library.
- [Plotly](https://github.com/plotly/plotly.rs): For the inspiration and ideas behind visualization libraries.
- Rust Community: For the support and development of an amazing programming language.
- [Polars](https://github.com/pola-rs/polars): For providing a fast and
efficient data manipulation library.
- [Plotly](https://github.com/plotly/plotly.rs): For the inspiration and ideas
behind visualization libraries.
- Rust Community: For the support and development of an amazing programming
language.
168 changes: 1 addition & 167 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,171 +1,5 @@
#![doc = include_str!("../README.md")]
#![allow(clippy::needless_doctest_main)]
//! # Plotlars
//!
//! <p align="center">
//! <a href="https://crates.io/crates/plotlars"><img alt="Crates.io" src="https://img.shields.io/crates/v/plotlars.svg"></a>
//! <a href="https://docs.rs/plotlars"><img alt="docs.rs" src="https://img.shields.io/docsrs/plotlars"></a>
//! <a href="https://github.com/your-repo/plotlars/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
//! </p>
//!
//!
//! Plotlars is a versatile Rust library that bridges the gap between the powerful Polars data analysis library and Plotly library. It simplifies the process of creating visualizations from data frames, allowing developers to focus on data insights rather than the intricacies of plot creation.
//!
//! ## Motivation
//!
//! The creation of Plotlars was driven by the need to simplify the process of creating complex plots in Rust, particularly when working with the powerful Polars data manipulation library. Generating visualizations often requires extensive boilerplate code and deep knowledge of both the plotting library and the data structure. This complexity can be a significant hurdle, especially for users who need to focus on analyzing and interpreting data rather than wrestling with intricate plotting logic.
//!
//! To illustrate this, consider the following example where a scatter plot is created without Plotlars:
//!
//! **Without Plotlars**
//!
//! ```rust
//! use plotly::{
//! common::*,
//! layout::*,
//! Plot,
//! Scatter,
//! };
//!
//! use polars::prelude::*;
//!
//! fn main() {
//! let dataset = LazyCsvReader::new("data/penguins.csv")
//! .finish().unwrap()
//! .select([
//! col("species").cast(
//! DataType::Categorical(
//! None,
//! CategoricalOrdering::default()
//! )
//! ),
//! col("flipper_length_mm").cast(DataType::Int16),
//! col("body_mass_g").cast(DataType::Int16),
//! ])
//! .collect().unwrap();
//!
//! let group_column = "species";
//! let x = "body_mass_g";
//! let y = "flipper_length_mm";
//!
//! let groups = dataset
//! .column(group_column).unwrap()
//! .unique().unwrap();
//!
//! let layout = Layout::new()
//! .title(Title::with_text("Penguin Flipper Length vs Body Mass"))
//! .x_axis(Axis::new().title(Title::with_text("Body Mass (g)")))
//! .y_axis(Axis::new().title(Title::with_text("Flipper Length (mm)")))
//! .legend(Legend::new().title(Title::with_text("Species")));
//!
//! let mut plot = Plot::new();
//! plot.set_layout(layout);
//!
//! for group in groups.iter() {
//! let group = group.get_str().unwrap();
//!
//! let data = dataset
//! .clone()
//! .lazy()
//! .filter(col(group_column).eq(lit(group)))
//! .collect().unwrap();
//!
//! let x = data
//! .column(x).unwrap()
//! .i16().unwrap()
//! .to_vec();
//!
//! let y = data
//! .column(y).unwrap()
//! .i16().unwrap()
//! .to_vec();
//!
//! let trace = Scatter::default()
//! .x(x)
//! .y(y)
//! .name(group)
//! .mode(Mode::Markers)
//! .marker(Marker::new().size(10).opacity(0.5));
//!
//! plot.add_trace(trace);
//! }
//!
//! plot.show();
//! }
//! ```
//!
//! In this example, creating a scatter plot involves writing substantial code to manually handle the data and configure the plot, including grouping the data by category and setting up the plot layout.
//!
//! **With Plotlars**
//!
//! Now, compare that to the same plot created using Plotlars:
//!
//! ```rust
//! use plotlars::{
//! ScatterPlot,
//! Plot,
//! Text,
//! };
//!
//! use polars::prelude::*;
//!
//! fn main() {
//! let dataset = LazyCsvReader::new("data/penguins.csv")
//! .finish().unwrap()
//! .select([
//! col("species").cast(
//! DataType::Categorical(
//! None,
//! CategoricalOrdering::default()
//! )
//! ),
//! col("flipper_length_mm").cast(DataType::Int16),
//! col("body_mass_g").cast(DataType::Int16),
//! ])
//! .collect().unwrap();
//!
//! ScatterPlot::builder()
//! .data(&dataset)
//! .x("body_mass_g")
//! .y("flipper_length_mm")
//! .group("species")
//! .size(10)
//! .opacity(0.5)
//! .plot_title(Text::from("Penguin Flipper Length vs Body Mass"))
//! .x_title(Text::from("Body Mass (g)"))
//! .y_title(Text::from("Flipper Length (mm)"))
//! .legend_title(Text::from("Species"))
//! .build()
//! .plot();
//! }
//! ```
//!
//! This is the output:
//!
//! ![Plot example](https://imgur.com/PkQ9fsc.png)
//!
//! With Plotlars, the same scatter plot is created with significantly less code. The library abstracts away the complexities of dealing with individual plot components and allows the user to specify high-level plot characteristics. This streamlined approach not only saves time but also reduces the potential for errors and makes the code more readable and maintainable.
//!
//! ## Installation
//!
//! ```bash
//! cargo add plotlars
//! ```
//!
//! ## Features
//!
//! - Seamless Integration with Polars: Leverage the power of Polars for efficient data manipulation and analysis.
//! - Support for Multiple Plot Types: Easily create bar, line, scatter, and other plot types.
//! - Customization: Modify plot appearance with an intuitive API.
//!
//! ## License
//!
//! This project is licensed under the MIT License. See the LICENSE.txt file for details.
//!
//! ## Acknowledgements
//!
//! - [Polars](https://github.com/pola-rs/polars): For providing a fast and efficient data manipulation library.
//! - [Plotly](https://github.com/plotly/plotly.rs): For the inspiration and ideas behind visualization libraries.
//! - Rust Community: For the support and development of an amazing programming language.

#[macro_use]
mod macros;
Expand Down

0 comments on commit 251c12f

Please sign in to comment.