plotly / Plotly.NET

interactive graphing library for .NET programming languages :chart_with_upwards_trend:
https://plotly.net
MIT License
663 stars 88 forks source link

Manually specify x-axis range on histogram #396

Closed mg-yolo-enterprises closed 1 year ago

mg-yolo-enterprises commented 1 year ago

Chart.Histogram using Plotly.NET.CSharp works very well at producing a histogram that fits exactly around the data provided. However, there are times when being able to specify the min/max limits of the axis would be beneficial to understanding the data in context.

In a case where X is a List<DateTime>, I determined that I can have some effect on the X-axis range by specifying the optional parameter: XBins: Bins.init(xMin, xMax, binSize) where the arguments are values of time converted to the unix epoch milliseconds.

However, xMin and xMax appear to have no effect if they would extend the X-axis beyond the limits of the non-zero bins in the dataset. It's as if there's an automatic ranging functionality that overrides manually specified bin start/end settings if they would leave leading or trailing zero bins.

Any suggestions for forcing the X-axis range to follow the start and end values provided in XBins? Or is there another way to accomplish this?

I've included an example histogram which, ideally, would have an X-Axis that starts at 8am and ends 24 hours later.

image

mg-yolo-enterprises commented 1 year ago

Figured this one out using

.WithXAxisStyle<DateTime, DateTime, string>(MinMax: (xMin, xMax).ToTuple())

Thanks!

image