Skip to content

Commit

Permalink
Merge pull request #107 from alxthor/improve_cbar
Browse files Browse the repository at this point in the history
Colorbars: Force cref closer to center of colorbar
  • Loading branch information
patrickscholz committed Feb 23, 2024
2 parents d64f711 + 45363b1 commit ac6a363
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tripyview/sub_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,10 +1577,19 @@ def do_setupcinfo(cinfo, data, do_rescale, mesh=None, tri=None, do_vec=False,
if cref==0.0:
cinfo['cref'] = cref
else:
# chose cref as center between cmin and cmax and round as coarsely as possible without
# 1. rounded value lying outside ]cmin, cmax[ (tolfac=1)
# 2. rounded value lying too far away from the middle (tolfac < 1)
# cref will be forced to lie in area maked with "+"
# cmin -----------++++++++++++++ ccenter ++++++++++++++----------- cmax
# |------ tolfac * (cmax - cmin) -------|
ccenter = (cinfo['cmax'] + cinfo['cmin'])/2
tolfac = 0.5 # tolfac=1 --> accept every cref that is between cmax and cmin. tolfac<1 --> cref closer to center
ctolerance = tolfac * (cinfo['cmax'] - cinfo['cmin'])/2
while True:
new_cref = np.around(cref, -np.int32(np.floor(np.log10(np.abs(cref)))-dez) )
#print(cref, new_cref, cinfo['cmin'], cinfo['cmax'])
if new_cref>cinfo['cmin'] and new_cref<cinfo['cmax']:
if new_cref>(ccenter - ctolerance) and new_cref<(ccenter + ctolerance):
break
else:
dez=dez+1
Expand Down

0 comments on commit ac6a363

Please sign in to comment.