KarthikRIyer / swiftplot

Swift library for Data Visualization :bar_chart:
Apache License 2.0
401 stars 39 forks source link

Missing points, strange errors in line graph #81

Closed WilliamHYZhang closed 4 years ago

WilliamHYZhang commented 4 years ago

When plotting line graph, some points aren't being plotted. Came across this bug when working on ML with S4TF and using SwiftPlot to visualize accuracy. Note that the "train" series for epoch 1 is missing.

image

It has something to do with the y axis scaling, it's really acting quite strange.

Here's a small example for reproducibility:

let x:[Float] = [0, 1, 2, 3]
let y:[Float] = [70, 80, 95, 100]

var lineGraph = LineGraph<Float,Float>(enablePrimaryAxisGrid: true)
lineGraph.addSeries(x, y, label: "Plot 1", color: .lightBlue)
lineGraph.plotTitle.title = "SINGLE SERIES"
lineGraph.plotLabel.xLabel = "X-AXIS"
lineGraph.plotLabel.yLabel = "Y-AXIS"
lineGraph.plotLineThickness = 3.0

lineGraph.drawGraph(renderer: agg_renderer)
display(base64EncodedPNG: agg_renderer.base64Png())

Output (point missing!): image

And when we just make a change to the first point:

let x:[Float] = [0, 1, 2, 3]
let y:[Float] = [0, 80, 95, 100]

var lineGraph = LineGraph<Float,Float>(enablePrimaryAxisGrid: true)
lineGraph.addSeries(x, y, label: "Plot 1", color: .lightBlue)
lineGraph.plotTitle.title = "SINGLE SERIES"
lineGraph.plotLabel.xLabel = "X-AXIS"
lineGraph.plotLabel.yLabel = "Y-AXIS"
lineGraph.plotLineThickness = 3.0

lineGraph.drawGraph(renderer: agg_renderer)
display(base64EncodedPNG: agg_renderer.base64Png())

Output (as expected): image

What is going on here?

WilliamHYZhang commented 4 years ago

Also, when dealing with decimals sometimes the graph doesn't show anything at all. For example, floats that are very close to each other in y-value.

KarthikRIyer commented 4 years ago

I'm not sure if @karwa's PR will fix this because it doesn't change the output in any way. Thank's for reporting this. I'll take a look as soon as I can.

karwa commented 4 years ago

Yes that PR doesn't fix this AFAIK.