0

Currently I have the following simple code which produces a nice looking graph with nice looking ticks (upper image)

ax.set_ylabel('Amplification Ratio', size=18)
ax.set_xlabel('Frequency [Hz]', size=18)
ax.set_xlim([0.05,0.75])
ax.set_ylim([0.5,10.])
ax.grid(b=True, which='minor')
ax.grid(b=True, which='major')

However, when I change the xlimit value to ax.set_xlim([**0.1**,0.75]) I get the messy ticks as shown in the bottom image.

I've searched the internet but nothing helped.

enter image description here

I would like only the "10^-1" to appear, in this exact format (not 0.1 or 1X10-1) and no other ticks.Just the log format one tick and that is all.

alina
  • 1
  • 1

1 Answers1

0

Have a look at the first answer in the following:

Modify tick label text

i.e. if your figure object is called fig, adding code like

fig.canvas.draw()
labels = [item.get_text() if item.get_text() == "10^-1" else "" for item in ax.get_xticklabels()]
ax.set_xticklabels(labels)

before showing the graph will remove the labels that arent "10^-1", i.e. the mess at the end of the ticks in your graph

Tarje Bargheer
  • 175
  • 3
  • 8
  • I would like only the "10^-1" to appear, in this exact format (not 0.1 or 1X10-1) and no other ticks.Just the log format one tick and that is all. – alina Aug 20 '18 at 09:42
  • I have updated the answer, specifying the needed call to draw the canvas first so the labels can be manipulated, as well as handling that ax.get_xticklabels() could position "10^-1" somewhere else than in position 0 - due to other calls in your code? – Tarje Bargheer Aug 20 '18 at 19:43