Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to visualize values on logarithmic scale on matplotalib?

I have vales with very small difference like... 0.000001. I want to visualize them on logarithmic scale. I am wondering how to do it in matplotlib.

Thanks a lot

like image 327
Shan Avatar asked Apr 02 '12 15:04

Shan


People also ask

How do you plot a log scale in Python?

pyplot library can be used to change the y-axis or x-axis scale to logarithmic respectively. The method yscale() or xscale() takes a single value as a parameter which is the type of conversion of the scale, to convert axes to logarithmic scale we pass the “log” keyword or the matplotlib. scale.

How do you change the scale on a graph in matplotlib?

To change the range of X and Y axes, we can use xlim() and ylim() methods.


3 Answers

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.axis

Simply add the keyword argument log=True

Or, in an example:

from matplotlib import pyplot
import math
pyplot.plot([x for x in range(100)],[math.exp(y) for y in range(100)] )
pyplot.xlabel('arbitrary')
pyplot.ylabel('arbitrary')
pyplot.title('arbitrary')

#pyplot.xscale('log')
pyplot.yscale('log')

pyplot.show()

enter image description here

like image 170
Cory Dolphin Avatar answered Sep 21 '22 16:09

Cory Dolphin


Since all other answers only mention the global pyplot.xscale("log") approach: You can also set it per axis, but then the syntax is:

ax.set_yscale("log")
like image 38
bluenote10 Avatar answered Sep 21 '22 16:09

bluenote10


You can use this piece of code:

import matplotlib.pyplot
# to set x-axis to logscale
matplotlib.pyplot.xscale('log')
# to set y-axis to logscale
matplotlib.pyplot.yscale('log')
like image 36
Thanasis Petsas Avatar answered Sep 22 '22 16:09

Thanasis Petsas