我想绘制一个x轴较高且不带标签但包含主要和次要刻度线的图。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns
perf = np.cumprod(1+np.random.normal(size=250)/100)
df = pd.DataFrame({'underwater': perf/np.maximum.accumulate(perf)-1})
sns.set_context('notebook')
sns.set_style('ticks', rc = {'axes.grid': True, 'axes.spines.left': True, 'axes.spines.right': False, 'axes.spines.bottom': True, 'axes.spines.top': False})
ax = plt.gca()
df.plot.area(ax=ax, label = 'underwater')
ax.xaxis.tick_top()
ax.xaxis.set_ticklabels([])
sns.despine(left=False, bottom=True, right=True, top = False, ax=ax)
答案 0 :(得分:0)
将最后一行添加到您的代码中。此外,您不需要tick_top()
行
ax = plt.gca()
df.plot.area(ax=ax, label = 'underwater')
# ax.xaxis.tick_top() # <----- This line is not needed
ax.xaxis.set_ticklabels([])
sns.despine(left=False, bottom=True, right=True, top = False, ax=ax)
# Add the following line to your code
ax.tick_params('x', length=8, width=2, color='red', which='major', direction='out')