如何在网格下方显示xaxis ticklabels?
ax.set_xticklabels([0.1, '', '', '', 0.5, '', '', '', '', 1.0], minor=True)
当我运行代码时,我得到下面的图。
如果我将代码行从
ax.set_xticks(np.arange(0, len(diameter_labels), 1))
到
ax.set_xticks(np.arange(0, len(diameter_labels), 1), minor=True)
这一次,我得到了下面的数字。
实际上,我想得到下面的数字。
import matplotlib.pyplot as plt
import os
import numpy as np
if __name__ == "__main__":
fig, ax = plt.subplots(figsize=(10, 3))
diameter_labels = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
row_labels = ['circle']
ax.grid(which="major", color="white", linestyle='-', linewidth=3)
ax.set_aspect(1.0)
for row_index, row_label in enumerate(row_labels):
for diameter_index, diameter_label in enumerate(diameter_labels):
circle=plt.Circle((diameter_index + 0.5, row_index + 0.5), radius=(diameter_label/(2*1.09)), color='gray', fill=True)
ax.add_artist(circle)
ax.set_xlim([0, len(diameter_labels)])
ax.set_xticklabels([])
ax.set_xticks(np.arange(0, len(diameter_labels), 1))
ax.tick_params(axis='x', which='minor', length=0, labelsize=30)
ax.set_xticklabels([0.1, '', '', '', 0.5, '', '', '', '', 1.0], minor=True)
ax.xaxis.set_ticks_position('bottom')
ax.tick_params(
axis='x', # changes apply to the x-axis
which='major', # both major and minor ticks are affected
bottom=False, # ticks along the bottom edge are off
top=False) # labels along the bottom edge are off
ax.xaxis.set_label_position('top')
ax.set_xlabel('Test', fontsize=40, labelpad=5)
ax.set_ylim([0, len(row_labels)])
ax.set_yticklabels([])
ax.tick_params(axis='y', which='minor', length=0, labelsize=12)
ax.set_yticks(np.arange(0, len(row_labels), 1))
ax.tick_params(
axis='y',
which='major',
left=False)
ax.grid(which='major', color='black', linestyle='-', linewidth=1)
filename = 'test.png'
figureFile = os.path.join('/Users/burcakotlu/Desktop', filename)
fig.savefig(figureFile)
plt.close()
1条答案
按热度按时间gkn4icbw1#
更换:
使用:
我明白了。阅读
help(ax.set_xticks)
了解更多信息。编辑以满足评论:
然后,根据您想要实现的目标修改标签列表,如下所示:
编辑第三次是魅力: