3

enter image description here

This plot is supposed to show differences in time, which can be both negative and positive values. Some differences are very small, while others are very large.

Can I scale the x-axis so that the resolution is very fine near x = 0 and coarse farther away from x = 0? Is it possible to have a logarithmic scale going outward from x = 0?

EDIT:

As suggested by @Evert, this solves the problem for me:

ax = gca()
...
ax.set_xscale("symlog")

and produces this plot:

enter image description here

clstaudt
  • 21,436
  • 45
  • 156
  • 239

2 Answers2

7

You can use the symlog setting in xscale(): http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xscale

It scales logarithmically (also on the negative side), apart from a limited section around zero (which can be set using further keywords, see the documentation): that section is scaled linearly, thus avoiding all log(0) problems.

See here for an example.

Community
  • 1
  • 1
3

I would make two subplots: plot the positive times in the right-hand subplot, and plot abs(negative times) in the left-hand subplot, with a reversed x-axis.

Is it possible to have a logarithmic scale going outward from x = 0?

No, because a logarithmic plot doesn't show zero --- as you approach the "left end" of the log-x axis, you go to negative infinity in log space, so you can't cross zero to get to the truly negative values. You have to cut zero out somehow.

Community
  • 1
  • 1
askewchan
  • 45,161
  • 17
  • 118
  • 134