0
0
Matplotlibdata~10 mins

Axis scales (linear, log) in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the y-axis scale to logarithmic.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 10, 100, 1000])
plt.yscale([1])
plt.show()
Drag options to blanks, or click blank then click option'
A'log10'
B'log'
C'logarithmic'
D'linear'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'logarithmic' instead of 'log'.
Using 'log10' which is not a valid scale name.
Forgetting to put the scale type in quotes.
2fill in blank
medium

Complete the code to set the x-axis scale to linear.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.xscale([1])
plt.show()
Drag options to blanks, or click blank then click option'
A'linear'
B'logarithmic'
C'log'
D'log10'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'log' when linear scale is needed.
Using 'logarithmic' which is not recognized.
Not putting the scale type in quotes.
3fill in blank
hard

Fix the error in the code to set the y-axis scale to logarithmic.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 10, 100, 1000])
plt.yscale([1])
plt.show()
Drag options to blanks, or click blank then click option'
Alogarithmic
B'logarithmic'
Clog
D'log'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the scale type without quotes causing a NameError.
Using 'logarithmic' which is not a valid scale name.
4fill in blank
hard

Fill both blanks to set the x-axis to logarithmic and y-axis to linear scale.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 10, 100, 1000])
plt.xscale([1])
plt.yscale([2])
plt.show()
Drag options to blanks, or click blank then click option'
A'log'
B'linear'
C'logarithmic'
D'log10'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'logarithmic' which is not recognized.
Not quoting the scale type strings.
Mixing up xscale and yscale.
5fill in blank
hard

Fill all three blanks to create a plot with x-axis logarithmic, y-axis logarithmic, and set the base of the log scale to 2.

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 4, 8, 16])
plt.xscale([1], base=[2])
plt.yscale([3], base=2)
plt.show()
Drag options to blanks, or click blank then click option'
A'log'
B2
C'linear'
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'linear' instead of 'log' for axes.
Not setting the base parameter correctly.
Using base 10 instead of 2.