Compare plots of $y=x^3$ for $-10 \le x \le 10$ using a logarithmic scale on the $x$-axis, $y$-axis, and both axes. What is the difference between using ax.set_xscale('log')
and ax.set_xscale('symlog')
?
The code below produces the six required plots.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10, 1000)
y = x**3
fig = plt.figure()
def do_plot(ax_no, axes, scale_type):
ax = fig.add_subplot(3, 2, ax_no)
ax.set_title('({})'.format(chr(96+ax_no)))
ax.plot(x, y)
for axis in axes:
if axis == 'x':
ax.set_xscale(scale_type)
else:
ax.set_yscale(scale_type)
do_plot(1, ('x',), 'log')
do_plot(2, ('x',), 'symlog')
do_plot(3, ('y',), 'log')
do_plot(4, ('y',), 'symlog')
do_plot(5, ('x', 'y'), 'log')
do_plot(6, ('x', 'y'), 'symlog')
fig.tight_layout()
plt.show()
(a) $x$-axis log, $y$-axis linear
(b) $x$-axis symlog, $y$-axis linear
(c) $x$-axis linear, $y$-axis log
(d) $x$-axis linear, $y$-axis symlog
(f) $x$-axis log, $y$-axis log
(f) $x$-axis symlog, $y$-axis symlog