A similar question was already asked here, but no answer was given. I have already experimented a bit with the FormatStrFormatter
but to no avail. There is also this post, but I am not sure if the answers can help in my case. To clarify: I know the 'sci'
ticklabel format exists, but for one I would like the format not to be 10e4
but 10^4
like it is the case when using a log scale, and also, each tick label should be formated that way, i.e. I don't want the 10e4
only once at the end of the axes, as shown in the first link. Additionally, I would like the unit also to be part of the tick label, in particular units that also come with powers like m^2
. Is that possible?
Asked
Active
Viewed 84 times
1

mapf
- 1,906
- 1
- 14
- 40
-
You should provide a [mcve] for your attempt with FormatStrFormatter. Or you could try using FuncFormatter, it will give you more control. Do you know where to find the documentation and examples? Do you actually want superscript exponents or just the `^`? – wwii Dec 19 '19 at 20:22
-
3See [this answer](https://stackoverflow.com/a/49330649/4124317). – ImportanceOfBeingErnest Dec 19 '19 at 20:27
-
2It's rather `g = lambda x,pos : "${}$ m${{}}^2$".format(f._formatSciNotation('%1.10e' % x))`. Unfortunately, there is no easier solution currently. – ImportanceOfBeingErnest Dec 19 '19 at 20:43
-
1@ImportanceOfBeingErnest I feel like the duplicate question should be edited to remove `Python 2.7`, since that's not relevant to the provided answers and maybe your formatting comment should be added to the duplicate answer so it can be found more easily. Just a thought. Mark as no longer needed after reading. Thanks – Trenton McKinney Dec 19 '19 at 20:55
-
@ImportanceOfBeingErnest: Thank you! I didn't find that post. I adapted your `MathTextSciFormatter` class now. It basically works as intended, however the values are off for some reason. `x` is the tick value I assume? Somehow it is always between 0 and 1 even though it should be orders of magnitudes different. I don't understand why. – mapf Dec 19 '19 at 23:42
-
1most probably you made a mistake somewhere, but it's close to impossible to know what's happening if you adapted that code. I suggest asking a new question and showing your adaption. – ImportanceOfBeingErnest Dec 19 '19 at 23:49
-
Ok so I figured out what the problem was. I normalized my image using `ImageNormalize` from the `astropy.visualization` (although I guess any normalization would have the same effect). So at first glance, it totally makes sense that because of this, all values are between 0 and 1. However, if I use default tick labels, the normalization doesn't have any effect on them. I wonder why. Should I open a new question for that? I don't rely on the normalization so for me it's fine, but maybe somebody else would like to know. Maybe add it as a caveat to your solution? – mapf Dec 20 '19 at 13:23
-
Or is the opposite actually the case, and your solution works as it should (I think it makes the most sense honestly, that if you use a normalization the colorbar reflects that), and this is actually unwanted behaviour from the default tick labels? – mapf Dec 20 '19 at 13:25