Python 绘图:X轴上的记号过多

Python 绘图:X轴上的记号过多,python,matplotlib,plot,Python,Matplotlib,Plot,第一个加载的绘图在X轴上有太多的记号(请参见图01) 如果我在X轴上使用缩放动作,绘图现在加载良好 你能给我一些建议,我可以在哪里搜索,因为绘图构造函数参数看起来不错 date_range = (735599.0, 735745.0) x = (735610.5, 735647.0, 735647.5, 735648.5, 735669.0, 735699.0, 735701.5, 735702.5, 735709.5, 735725.5, 735728.5, 735735.5, 73573

第一个加载的绘图在X轴上有太多的记号(请参见图01)

如果我在X轴上使用缩放动作,绘图现在加载良好

你能给我一些建议,我可以在哪里搜索,因为绘图构造函数参数看起来不错

date_range = (735599.0, 735745.0)
x = (735610.5, 735647.0, 735647.5, 735648.5, 735669.0, 735699.0, 735701.5, 735702.5, 735709.5, 735725.5, 735728.5, 735735.5, 735736.0)
y = (227891.25361545716, 205090.4880046467, 208352.59317388065, 175462.99296699322, 98209.836461969651, 275063.37219361769, 219456.93600708069, 230731.12613806152, 209043.19805037521, 218297.51486296533, 208036.88967207001, 206311.71988471842, 216036.56824433553)
y0 = 218206.79192
x_after = (735610.5, 735647.0, 735647.5, 735701.5, 735702.5, 735709.5, 735725.5, 735728.5, 735735.5, 735736.0)
y_after = (227891.25361545716, 205090.4880046467, 208352.59317388065, 219456.93600708069, 230731.12613806152, 209043.19805037521, 218297.51486296533, 208036.88967207001, 206311.71988471842, 216036.56824433553)
linex = -39.1175584541
liney = 28993493.5251

ax.plot_date(x, numpy.array(y) / y0, color='r', xdate=True, marker='x')
ax.plot_date(x_after, numpy.array(y_after) / y0, color='r', xdate=True)
ax.set_xlim(date_range)
steps = list(ax.get_xlim())
steps.append(steps[-1] + 2)
steps = [steps[0] - 2] + steps
ax.plot(steps, numpy.array([linex * a + liney for a in steps]) / y0, color='b')
谢谢你的帮助。
曼纽尔

我不确定我是否完全理解你想要做什么,但你的X字裤轮换是否足够

# Add this code at the end of your script
# It will rotate the labels contained in your date range
plt.xticks(rotation=70)

如果我测试你的代码,我有7个标签,但是旋转参数改为0(水平)

如果你有太多的
xtick
标签,以至于它们在绘图上都被遮住了,你可以使用。参数是标签应用到的点、标签本身和可选旋转

import numpy as np
import matplotlib.pyplot as plt
y = np.arange(10000)
ticks = y - 5000
plt.plot(y)
k = 1000
ys = y[::k]
ys = np.append(ys, y[-1])
labels = ticks[::k]
labels = np.append(labels, ticks[-1])
plt.xticks(ys,labels, rotation='vertical')
plt.show()
plt.close()

我很确定这就是你想要的。您可能可以在matplotlib库中找到使用示例。当我观看get_xticks()时,起初一切正常,但在调用set_xlim(日期范围)之后,我在X轴上有太多的记号。是否使用X轴日期执行此操作。@johnstamos-??不确定您的评论意味着什么-概念是一样的,您可以为勾号位置/标签选择数据的子集,无论它们是日期还是数字。@johnstamos-这个问答非常古老,有很多方法可以解决这个问题。例如-看起来是一种简洁的处理方法。也许需要一个新的答案,但有许多(众多)的SO问答在处理这个问题。