0

I am plotting some contours with tricontourf. I want the colormap to be scaled in log values and tick labels and colours bounds to be in log base 2. Here's my code:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import matplotlib.ticker as ticker
import matplotlib.colors as colors

section = 'T7'

data = np.loadtxt( section + '_values.dat')
x = data[:,0]
y = data[:,1]
z = data[:,2]

triang = tri.Triangulation(x,y)

fig1, ax1 = plt.subplots()
ax1.set_aspect('equal')
bounds = [2.**-1,2.**1,2**3,2**5,2**7,2**9]
norm = colors.LogNorm()
formatter = ticker.LogFormatter(2)
tcf = ax1.tricontourf(triang, z, levels = bounds, cmap='hot_r', norm = norm )

fig1.colorbar(tcf, format=formatter)


plt.show()

And here's the result:

enter image description here

What are thos ugly minor ticks and how do I get rid of them? Using Matplotlib 3.3.0 an Mac OS

user2078621
  • 111
  • 3
  • 12

1 Answers1

2

You could use cb.ax.minorticks_off() to turn off the minor tick and cb.ax.minorticks_on() to turn it on.

cb = fig1.colorbar(tcf, format=formatter)
cb.ax.minorticks_off()

matplotlib.pyplot.colorbar returns a Colorbar object which extends ColorbarBase.

You can find that two functions in the document of class matplotlib.colorbar.ColorbarBase.

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
  • Thank you very much @Ynjxsjmh, that indeed turns the minor ticks off. But I'd also like to know what those ticks are and how they are set. It seems like they represent a different logarithmic base (maybe 10?). – user2078621 Aug 17 '20 at 09:39
  • Three variables `bounds`, `norm` and `formatter` defined in your code are related with ticks in colorbar. See [colorbar format](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.colorbar.html), [LogNorm](https://matplotlib.org/api/_as_gen/matplotlib.colors.LogNorm.html). – Ynjxsjmh Aug 17 '20 at 12:17