Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Created June 9, 2020 15:33
Show Gist options
  • Save Vindaar/cb42e7a7787a5de5f40e7dcfd80f7b5f to your computer and use it in GitHub Desktop.
Save Vindaar/cb42e7a7787a5de5f40e7dcfd80f7b5f to your computer and use it in GitHub Desktop.
import plotly, random, sequtils
import json # to modify json
import strformat # to format the tick texts
# let's assume the 28 correspond to 28 inches and we want to print the
# x axis values in pixels using a dpi of 72.27
var zs = newSeqWith(28, newSeq[float32](28))
for x in 0 ..< 28:
for y in 0 ..< 28:
zs[x][y] = rand(1.0)
# create a heatmap and convert to a `PlotJson` object
let plt = heatmap(zs).toPlotJson
# replace the existing layout["xaxis"] with custom vals
plt.layout["xaxis"] = %* {
"tickvals" : toSeq(0 .. 27),
"ticktext" : toSeq(0 .. 27).mapIt(&"{it.float * 72.27:.2f}"),
"title" : "inches -> pixels"
}
plt.show()
@Vindaar
Copy link
Author

Vindaar commented Jun 9, 2020

newplot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment