我想将垂直轴的刻度标签放置在刻度上。基本上,问题在于沿轴移动标签。我已经看到了将标签从轴上移开,旋转标签的解决方案,但是我的要求似乎不太常见。
import matplotlib.pyplot as plt
ax = plt.gca()
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
line = plt.Line2D([0,1],[0,1], color='black', zorder=2)
plt.gca().add_line(line)
plt.show()
答案 0 :(得分:2)
您可以将标签底部对齐,以使其与刻度线相比更偏向顶部。
def is_in(val, lst):
"""
is_in is designed to check if a word is in a list of words in alphabetical order.
:param val: the word to look for
:param lst: the lst of words to check
"""
curlen = len(lst) # saving processing power
if ((curlen == 1) and (lst[0] != val)) or (curlen == 0): # base case
return False
else:
center = curlen // 2
pivot = lst[center]
# print("pivot: " + str(pivot))
# print("val: " + str(val))
if pivot == val: # base case 2
return True
elif pivot > val:
return is_in(val, lst[:center])
else:
return is_in(val, lst[center:])
当不想导入pyplot时,等效于import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.tick_params(axis="y", length=20, pad=0)
plt.setp(ax.get_yticklabels(), va="bottom", ha="left")
plt.show()
plt.setp