Created
July 1, 2020 23:38
-
-
Save a-poor/1b2e25634795c73cdb6796338fc2d20b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_scale(dmin,dmax,rmin,rmax): | |
dwidth = dmax - dmin | |
rwidth = rmax - rmin | |
map_ = rwidth / dwidth | |
def scale(n): | |
return (n - dmin) * map_ + rmin | |
return scale | |
xscale = make_scale( | |
layout['data']['time_min'], | |
layout['data']['time_max'], | |
layout['plot']['xmin'], | |
layout['plot']['xmax'] | |
) | |
yscale = make_scale( | |
layout['data']['price_min'], | |
layout['data']['price_max'], | |
layout['plot']['ymax'], | |
layout['plot']['ymin'] | |
) | |
timerange = range( | |
layout['data']['time_min'], | |
layout['data']['time_max']+1 | |
) | |
xticks = [{"text":f"{i}:00","pos":xscale(i)} for i in timerange] | |
pricerange = range( | |
layout['data']['price_min'], | |
layout['data']['price_max']+1 | |
) | |
yticks = [{"text":f"${i}","pos":yscale(i)} for i in pricerange] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment