cpmech / plotpy

Rust plotting library using Python (Matplotlib)
MIT License
65 stars 6 forks source link

Design principle of plotpy #67

Closed wangjiawen2013 closed 2 months ago

wangjiawen2013 commented 2 months ago

Hi, I want to add some scientific plots such as boxplot, violin plot, probality density plot and so on. So I wanna know more about the design principle of plotpy. There are a lot of parameters in matplotlib, it's hard to include all these parameters in plotpy, though many parameters are rarely used. I notice that there is a parameter called extra in barplot.rs:

pub struct Barplot {
    label: String,             // Name of this bar in the legend
    colors: Vec<String>,       // Colors for each bar
    width: f64,                // Width of the bars
    bottom: Vec<f64>,          // bottom coordinates to stack bars
    with_text: Option<String>, // Text to be added to each bar (aka, bar_label)
    horizontal: bool,          // Horizontal barplot
    x_errors: Vec<f64>,        // Shows x-error icons on horizontal bars
    extra: String,             // Extra commands (comma separated)
    buffer: String,            // buffer
}

So we can set any parameters used in matplotlib barplot using extra. But not all structs in plotpy have extra. So could you tell about the parameter setting strategy and design principle of plotpy ? Then we can add plotting functions in consistent with your style as possible as we can.

cpmech commented 2 months ago

Hi, thanks again for your interest in Plotpy.

The basic "design principle" of Plotpy is to have multiple functions to set the parameters of a plot instead of having a function with various parameters, as in Matplotlib. That's why we have things such as:

set_line_alpha
set_line_color
set_line_style
set_something...

Instead of:

plot(x, y, alpha=a, color=c, line_style=ls, ...)

The main "feature" of Plotpy is the GraphMaker trait, which is implemented by Curve, Contour, Text, etc. The Plot structure can then generate the Python script. The Plot structure also has many functions to configure the plot.

I have implemented the set_extra function for most structures from version 1.7.