-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Closed
Description
matplotlib allows to generate nice ticks for given image. But I had reverse task - generate custom color image (ratio of two images - pixel wise ratio define color and pixel wise average define intensity) with custom color bar with nice ticks. To do so I need to know ticks before I can make image, and the only thing that is known is approximate center value and range ±50%. I had to use code from below, but it would be nice to have easy access to built-in matplotlib function that generates ticks array for wanted range
# Make equdistant ticks for given range
def Ticks4Range(Range, MinTickCount = 5):
Sign = numpy.sign(Range[1] - Range[0])
TickStep = Sign * (Range[1] - Range[0]) / MinTickCount
Digits = numpy.floor(numpy.log10(TickStep) + 1) - 1
TickStep = (TickStep / 10**Digits)
if TickStep < 2:
TickStep = 1
elif TickStep < 2.5:
TickStep = 2
elif TickStep < 5:
TickStep = 2.5
else:
TickStep = 5
TickStep = TickStep * 10**Digits
Digits = numpy.floor(numpy.log10(numpy.max(Range)) + 1) - 1
#TickRange = numpy.ceil(Range[0] / TickStep) * TickStep, numpy.floor(Range[1] / TickStep) * TickStep
#Ticks = numpy.linspace(TickRange[0], TickRange[1], numpy.round((TickRange[1] - TickRange[0]) / TickStep * Sign))
Ticks = numpy.arange(numpy.ceil(Range[0] / TickStep * Sign) * Sign * TickStep, Range[1]*(1 + 0.01*Sign*numpy.sign(Range[1])), TickStep * Sign)
return TicksI use it this way
>>> custom.Ticks4Range(57.86 * numpy.array([0.5, 1.5]), 3)
array([ 30., 40., 50., 60., 70., 80.])Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels