简体   繁体   English

X-ticks 与 Matplotlib 重叠

[英]X-ticks overlapping with Matplotlib

I have a script for plotting big data sets.我有一个用于绘制大数据集的脚本。 I have a problem while setting the xticks in my plot.在我的情节中设置 xticks 时遇到问题。 I have tried the following code:我尝试了以下代码:

 plt.xticks(configDBcomplete.index),max(configDBcomplete.index[-1]),5),data,rotation=90, fontsize= 12

The problem is that I have more than 2000 data points for x and the ticks get overlapped.问题是我有超过 2000 个 x 数据点,并且刻度重叠。 I want to have ticks at every 5th data point.我想在每 5 个数据点有一个刻度。 I have tried using np.arange as:我曾尝试使用np.arange作为:

 plt.xticks(np.arange(min(configDBcomplete.index),max(configDBcomplete.index[-1]),5),data,rotation=90, fontsize= 12

but it plots the first 50 data points along the plot and not the corresponding ones.但它沿图绘制前 50 个数据点,而不是相应的数据点。 Any idea how to solve this?知道如何解决这个问题吗?

Currently you are using the whole data for setting the x-ticklabels.目前您正在使用整个data来设置 x-ticklabels。 The first argument to the xticks() function is the location of the ticks and the second argument is the tick labels. xticks()函数的第一个参数是刻度的位置,第二个参数是刻度标签。

You need to use indexing to get every 5th data point (corresponding to the ticks).您需要使用索引来获取每 5 个数据点(对应于刻度)。 You can access it using [::5] .您可以使用[::5]访问它。 So you need to pass data[::5] to your xticks() as所以你需要将data[::5]传递给你的xticks()作为

plt.xticks(np.arange(min(configDBcomplete.index),max(configDBcomplete.index[-1]),5),data[::5],rotation=90, fontsize= 12)

You can also use range() as您还可以使用range()作为

plt.xticks(range(min(configDBcomplete.index),max(configDBcomplete.index[-1]),5),data[::5],rotation=90, fontsize= 12)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM