6

I'm plotting a log plot using matplotlib. My values go from 1 to 35.

fig=plt.figure(figsize=(7,7))
fig.subplots_adjust(top=0.75, right=0.9)
ax=fig.add_subplot(111)
ax.plot(x, y, marker='o', color='black', ls='')
ax.set_xscale('log')
ax.set_yscale('log')

I would like to set the x- and y-axis starting from values lower than 1, but if I use

ax.axis([-10,45,-10,45])

it doesn't work. I know that it is because I'm using a log scale, but is there a way to solve the problem obtaining the axis I want?

sodd
  • 12,482
  • 3
  • 54
  • 62
Marika Blum
  • 907
  • 2
  • 8
  • 7
  • @tcaswell I actually believe that OP wants to have axes with _negative_ values, as it is specified that the values to be plotted are ranging from 1 to 35, as well as the title of the post. With axis-limits at `[1e-10, 1e45, 1e-10, 1e45]` this data will be _very_ hard to represent in any informative way, as the limits are several orders of magnitude larger than the actual data. – sodd Jun 02 '13 at 12:14
  • @nordev ah, I missed that. – tacaswell Jun 02 '13 at 16:13

1 Answers1

12

Use the 'symlog' argument for ax.set_xscale, as this is linear in a small interval around zero and logarithmic elsewhere.

You can even set the interval where you want the axis to be linear with the keyword argument linthreshx (linthreshy for ax.set_yscale), which accepts a tuple consisting of the limit on the negative and the positive side respectively, i.e. linthreshx=(-linthresh,linthresh), or simply linthreshx=linthresh.

ax.set_xscale('symlog')
ax.set_yscale('symlog')
ax.axis([-10,45,-10,45])
Félix Faisant
  • 191
  • 1
  • 1
  • 11
sodd
  • 12,482
  • 3
  • 54
  • 62