SciNim / nim-plotly

plotly wrapper for nim-lang
https://scinim.github.io/nim-plotly/
MIT License
181 stars 15 forks source link

Auto width bar plot #21

Closed Vindaar closed 6 years ago

Vindaar commented 6 years ago

edit: see the comment below for an update.

~Based on the "save image" PR.~

~This is still WIP, because I only hacked it in, without thinking too much about potential consequences for other use cases than I had so far.~

~It allows to automatically calculate the bin with of a bar plot based on the given x sequence. x should contain the bin edges of the resulting histogram. The main reason to implement it, is to allow unequal bin width, like for example in the following plot:~

The following is not going to be part of this PR, but left as ideas

Possible future feature (afaik CERN's ROOT allows this):

so that

let tupRange: tuple[low, high: float] # some range tuple
let nBins: int
let nonLinearBins = linspace(tupRange.low, tupRange.high, nBins).mapIt(toBin(it, params)

where linspace is the numpy equivalent. The idea would be a simple function call like

    f1 = Trace[float](`type`: PlotType: Histogram,
                      range: (0.0, 50.0),
                      nBins: 100,
                      binning: "1.5 * x + 2.3 / x")
    f2 = Trace[float](`type`: PlotType: Histogram,
                      range: (0.0, 50.0),
                      nBins: 100,
                      binning: toBin,
                      binningParams: params)    

Typing this feature here though makes me feel like the user convenience vs. the maintenance effort might not be worth it though, haha. I'll leave this here as a reference though. But hmm, the feature using the math expression library would be neat...

brentp commented 6 years ago

While this is cool idea, I agree with your concern about the maintenance (and documentation) burden. Maybe having an example that does some of this, without adding to the library would be preferable.

Vindaar commented 6 years ago

Only took me several months, but finally went back to finish this PR.

Since just adding an option to calculate the width of bars automatically, we can now have more fine grained control. Either set a specific width, set individual widths for each element or have the width calculated automatically (in addition to the default of course).

Also allows the bars to be interpreted such that the location represents the left edge of the bar, instead of the center.

Finally, also adds the option to change the orientation to horizontal, if desired.

edit: I named the examples starting from 14, assuming @remigijusj will be merged before. I'll rebase this PR onto the then master.

brentp commented 6 years ago

I merged the contour PR. Ready for rebase.

Vindaar commented 6 years ago

Rebased and fixed a bug. :)

brentp commented 6 years ago

nice!