Complete the code to set the y-axis to a logarithmic scale.
import matplotlib.pyplot as plt plt.plot([1, 10, 100, 1000]) plt.yscale([1]) plt.show()
Use plt.yscale('log') to set the y-axis to a logarithmic scale.
Complete the code to set the x-axis to a symmetric logarithmic scale.
import matplotlib.pyplot as plt plt.plot([-1000, -10, 0, 10, 1000]) plt.xscale([1]) plt.show()
Use plt.xscale('symlog') to set the x-axis to a symmetric logarithmic scale, which handles negative and zero values.
Fix the error in the code to correctly set the y-axis to a symmetric logarithmic scale with a linear threshold of 1.
import matplotlib.pyplot as plt plt.plot([-5, -1, 0, 1, 5]) plt.yscale([1], linthresh=1) plt.show()
Use plt.yscale('symlog', linthresh=1) to set a symmetric log scale with a linear region around zero.
Fill both blanks to create a plot with x-axis on symmetric log scale and y-axis on log scale.
import matplotlib.pyplot as plt plt.plot([-100, -10, 0, 10, 100], [1, 10, 100, 1000, 10000]) plt.xscale([1]) plt.yscale([2]) plt.show()
Set plt.xscale('symlog') for symmetric log on x-axis and plt.yscale('log') for log scale on y-axis.
Fill all three blanks to create a dictionary comprehension that maps each number to its log scale value, but uses linear scale for values near zero.
import numpy as np numbers = [-10, -1, 0, 1, 10] scale_map = {n: np.sign(n) * np.log10(abs(n)) if abs(n) > [1] else n for n in numbers if n != [2] or n == [3]
The comprehension uses a threshold of 1 to apply log10 only for values with absolute value greater than 1. It excludes zero from log calculation but includes it linearly.