![](/img/trans.png)
[英]How to move specific x-axis (minor) tick labels to the top of a figure in matplotlib?
[英]Matplotlib x-axis at the top, no x axis label, no major tick labels, but outer major and minor tick wanted
我想绘制一个没有标签的上 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)
将最后一行添加到您的代码中。 此外,您不需要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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.