简体   繁体   English

设置为“in”时,Pcolormesh 次轴刻度缺失

[英]Pcolormesh secondary axis ticks missing when set as 'in'

I have an issue when setting the tick direction to direction='in' when using the secondary_xaxis function.在使用secondary_xaxis function 时将刻度方向设置为direction='in'时出现问题。 They appear only when set to out它们仅在设置为out时出现

Here is a MWE:这是一个MWE:

import matplotlib.pyplot as plt
import numpy as np


def invert(x):
    return (x+1)**-1


dx, dy = 0.15, 0.05

# generate 2 2d grids for the x & y bounds
y, x = np.mgrid[slice(-3, 3 + dy, dy),
                slice(-3, 3 + dx, dx)]
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()


fig = plt.figure()
ax = fig.add_subplot(111)

ax.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)

ax.set_xlabel(r'normal')
ax.tick_params(direction='in')

secax = ax.secondary_xaxis('top', functions=(invert, invert))
secax.set_xlabel(r'invert')

secax.tick_params(direction='in')

Here is the output:这是 output:

在此处输入图像描述

But setting secax.tick_params(direction='out') gives the correct output:但是设置secax.tick_params(direction='out')给出了正确的 output:

在此处输入图像描述

Anyone has an idea how to solve that?任何人都知道如何解决这个问题?

Thanks谢谢

Changing the zorder seems to fix this:更改zorder似乎可以解决此问题:

secax = ax.secondary_xaxis('top', functions=(invert, invert), zorder=3)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM