![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to visualize values on logarithmic scale on matplotalib?
To visualize values on logarithmic scale on matplotlib, we can use yscale('log').
Steps
Import matplotlib nd numpy.
Set the figure size and adjust the padding between and around the subplots.
Create x and y data points using numpy.
Use yscale('log') to visualize the values on a logarithmic scale.
Plot x and y data points using plot method.
Place a legend on the figure.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(1, 100, 1000) y = np.log(x) # logarithmic scale plt.yscale('log') # Plot the x and y data points plt.plot(x, y, c="red", lw=3, linestyle="dashdot", label="y=log(x)") # Place the legend plt.legend() # Display the plot plt.show()
Output
It will produce the following output −
Advertisements