情节:X ax上有太多的刻度

时间:2015-07-08 13:20:41

标签: python matplotlib plot

第一个加载的绘图在X ax上有太多刻度(参见image01)。

enter image description here

如果我在X ax上使用缩放动作,则图表现在已经很好地加载了。

enter image description here

你可以给我一些建议,我可以搜索,因为Plot构造函数参数似乎很好。

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')

感谢您的帮助。 曼努埃尔

2 个答案:

答案 0 :(得分:1)

如果你有太多的xtick labels,那么多,他们都会在情节中被挤在一起,你可以使用pyplot.xticks来减少它们。参数是标签应用的点,标签本身和可选的旋转。

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()

enter image description here

答案 1 :(得分:0)

我不确定我到底知道你想要做什么,但是你的xticklabels轮换对你来说是否足够?

# 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(水平)

相关问题