1

I have a script for plotting big data sets. I have a problem while setting the xticks in my plot. 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. I want to have ticks at every 5th data point. I have tried using np.arange as:

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. Any idea how to solve this?

1 Answer 1

1

Currently you are using the whole data for setting the x-ticklabels. The first argument to the xticks() function is the location of the ticks and the second argument is the tick labels.

You need to use indexing to get every 5th data point (corresponding to the ticks). You can access it using [::5]. So you need to pass data[::5] to your xticks() as

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

You can also use range() as

plt.xticks(range(min(configDBcomplete.index),max(configDBcomplete.index[-1]),5),data[::5],rotation=90, fontsize= 12)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.