Two tick labels overlap in the plot with symlog scale

Question:

I have made a plot with symlog on x-axis, and intend to make the linear region short enough (linscalex = 0.2). Please see my graph. However, the first tick label (1e-2) of the log region overlaps with the origin (0). Is there anyway to remove the tick label 1e-2?

Here is my code

plt.xscale('symlog', linthreshx = 0.05, 
           subsx = range(2,10), linscalex = 0.2)

enter image description here

Asked By: Augustin Pan

||

Answers:

As @ImportanceOfBeingErnest noted in the comments, you can simply set the ticks explicitly with

plt.gca().set_xticks([0, .1, 1, 10])

But since you ask for a more general solution, I thought to provide one – you can get the existing xticks and simply remove the second one indiscriminately with the following (probably a way to collapse this into a one-liner)

ticks = plt.xticks()[0]
ticks[1] = ticks[0]
plt.xticks(ticks[1:])

Obviously this is a bit of a blunt approach as it will always remove the second label, even if it isn’t interfering.

Answered By: Ghost

I was wondering that how i can remove 0?
plt.gca().set_xticks([0.01, 0.1, 1.0,10.0]) seems does’t work.

Answered By: Vincent Zhang
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.