Vindaar / ggplotnim

A port of ggplot2 for Nim
https://vindaar.github.io/ggplotnim
MIT License
176 stars 15 forks source link

Raster plot has white lines for big plots and doesn't use xlim and ylim correctly #107

Open HugoGranstrom opened 3 years ago

HugoGranstrom commented 3 years ago

Code to reproduce:

import ggplotnim, numericalnim, sequtils

for N in [10, 15, 20, 25, 30, 35, 37, 40]:
  let xRow: seq[float] = linspace(0.0, 10.0, N)
  let yCol: seq[float] = linspace(0.0, 10.0, N)
  let z: seq[float] = newSeqWith(N*N, 1.0)
  var x, y: seq[float]
  for xi in xRow:
    for yi in yCol:
      x.add xi
      y.add yi
  let df = seqsToDf(x, y, z)
  ggplot(df, aes("x", "y", fill = "z")) +
    geom_raster() +
    scale_x_continuous() + scale_y_continuous() +
    scale_fill_continuous(scale = (low: -70.0, high: 70.0)) +
    xlim(0.0, 10.0) + ylim(0.0, 10.0) +
    ggsave("grid" & $N & ".png", width = 900, height = 800)

Result:

Expected behavior

Further note

It has the correct number of squares, N, draw out but the relevant range (0-10) only has N - 1 squares. This could lead to multiple points inside the same square potentially.

Vindaar commented 3 years ago

The white lines are fixed with #108.

geom_raster not respecting x/ylim is still an open issue though, which is why I'm leaving this open for the time being.