Search code examples
pythonmatplotlibplotloglog

Matplotlib pyplot: Is it possible to have exponential axis?


i need "the opposite" of loglog for my pyplot chart. How can i achive exponential axis?

Data looks like:

x = [1, 2, 4]
y = [1, 2, 4]
z = [2, 2, 2]

quadranten = plt.figure()
s = [20*4**n for n in z]    

fig, ax = plt.subplots()
ax.axis([1, 5, 1, 5])
ax.loglog() <-- opposite function?

xstart, xend = ax.get_xlim()
ax.xaxis.set_ticks(np.arange(xstart, xend, 0.712123))
ax.xaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))

ystart, yend = ax.get_ylim()
ax.yaxis.set_ticks(np.arange(ystart, yend, 0.712123))
ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1f'))

plt.xlabel('x')
plt.ylabel('y')

plt.scatter(x,y,s=s)
plt.show()

The goal is the x axis to have evenly sized steps: 0, 1, 2, 4, 8,... Same for the y axis with evenly sized steps getting exponentially bigger by a factor (for example two): 0, 1, 2, 4, 8, ...

Is this possible?

Something like this: exponential


Solution

  • loglog takes arguments basex and basey that control the base of the logarithms:

    loglog(arange(1,100), arange(1,100)**2, basex=2, basey=2)
    

    enter image description here