Ohm
Ohm

Reputation: 2442

Matplotlib: changing the spacing between ticks

I am plotting a 2D array using pcolormesh of matplotlib using this code:

import matplotlib.pyplot as plt
import numpy as np

# generate 2 2d grids for the x & y bounds
y = np.linspace(1/2.0,2.0,100)
x = np.linspace(0.00001,2,100)

y, x = np.meshgrid(y,x)

z = (1 - x / 2. + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)

z = z[:-1, :-1]

z_min, z_max = -np.abs(z).max(), np.abs(z).max()


plt.pcolormesh(x, y, z)

# set the limits of the plot to the limits of the data
plt.axis([x.min(), x.max(), y.min(), y.max()])
plt.colorbar()

And I get this figure: 2Darray

I would like though that the distance between the 1/2 and 1 ticks on the y-axis will be the same as the distance between the 1 and 2 ticks - someone has an idea how to do that?

Upvotes: 2

Views: 150

Answers (1)

Ardweaden
Ardweaden

Reputation: 887

Why don't you just make y axis logarithmic?

plt.pcolormesh(x, y, z)
plt.yscale('log')
plt.yticks([0.5,1,2],[0.5,1,2])

Upvotes: 1

Related Questions