Logarithmically scaled small marks on the matplotlib matrix panel?

I'm having trouble adjusting the pcolormesh graph with a color bar that includes logarithmically spaced small marks on the color bar.

The closest I came, it’s something like this:

import matplotlib import matplotlib.pyplot as plt import numpy as np xbins = np.linspace(0, 1, 50) ybins = np.linspace(0, 1, 50) data = np.random.random((49,49)) fig, ax = plt.subplots() im = ax.pcolormesh(xbins, ybins, data, norm=matplotlib.colors.LogNorm()) cb = fig.colorbar(im) cb.ax.minorticks_on() plt.savefig('test.png') 

The problem with this solution is that minor ticks are evenly distributed in the log space:

enter image description here

I would like to adjust the plot so that I have evenly spaced small ticks in linear space that should be displayed unevenly on this section.

I know that I can manually set label tags of a smaller size using FixedFormatter , but I would prefer not to do this if possible, since I will do a lot of charts automatically.

+6
source share
2 answers

Added for posterity:
From this answer: @JoeKington fooobar.com/questions/806010 / ... :

 minorticks = p.norm(np.arange(1, 10, 2)) cb.ax.xaxis.set_ticks(minorticks, minor=True) 

It is annoying that you have to manually create checkmarks, but it seems to work.

+1
source

I think the best way for checkboxes of custom columns is to use the "ticks" argument of the fig.colorbar method and not try to modify the attributes of the ax containing the colorbar.

 from matplotlib.ticker import LogLocator "..." cb = fig.colorbar(im, ticks = LogLocator(subs=range(10))) 

enter image description here

+3
source

Source: https://habr.com/ru/post/974232/


All Articles