I have a scatter plot that displays the x (columns numbered 1 to 153) and y (mean of the column values), with a 95% confidence interval.
Since the plot is quite small, I wanted to show the ticks at every x position, but only have the labels every 10 elements.
Below is the code I started with:
df.sort_values(by=["Peak number"], inplace=True)
columns = list(df.iloc[:,2:].columns)
columns = np.asarray(columns, dtype='float')
means = df.iloc[:,2:].mean(axis = 0)
fig, ax = plt.subplots(figsize=(8, 6))
ax.plot(columns, means, "-", color="0.1", linewidth=1.5, alpha=0.5, label="Fit")
ax.set_xlabel('Peak number')
ax.set_ylabel('Mean ratio')
Using the Matplotlib documentation error guide, I tried ensuring my x values were integer numbers, but to no avail.
columns = np.asarray(columns, dtype='float')
Following that, I tried to manually set the x-axis tick labels using the xticks function. While that solved part of the issue (ie. only displayed the labels that I wanted), it didn't display the ticks without labels for all other x values.
plt.xticks(np.arange(0, len(columns) + 1, 10))
Only wanted labels, but no ticks
Alternatively, I could remove all the tick labels, including the ones I wanted to keep.
ax.set_xticks(np.arange(0, len(columns) + 1, 1), "")
All ticks, but not wanted labels
Essentially, I am trying to combine removing all tick labels, with manually including only the labels that I want. Is there a way to do this simply?