2012-04-02 53 views
5

Tengo valles con una diferencia muy pequeña como ... 0.000001. Quiero visualizarlos en escala logarítmica. Me pregunto cómo hacerlo en matplotlib.cómo visualizar valores en escala logarítmica en matplotalib?

Muchas gracias

+0

duplicado posible de [ Trazar ejes logarítmicos con matplotlib en python] (http://stackoverflow.com/questions/773814/plot-logarithmic-axes-with-matplotlib-in-python) – bluenote10

Respuesta

15

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

sólo tiene que añadir la palabra clave argumento log=True

O, en un ejemplo:

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

1

Se puede utilizar esta pieza de código:

import matplotlib.pyplot 
# to set x-axis to logscale 
matplotlib.pyplot.xscale('log') 
# to set y-axis to logscale 
matplotlib.pyplot.yscale('log') 
2

En lugar de plot, puede utilizar semilogy:

import numpy as npy 
import matplotlib.pyplot as plt 
x=npy.array([i/100. for i in range(100)]) 
y=npy.exp(20*x) 
plt.semilogy(x, y) 
plt.show() 

Pero no estoy del todo seguro de lo que espera ganar al usar una escala logarítmica. Cuando dice "pequeña diferencia", ¿quiere decir que los valores podrían ser algo así como 193.000001 y 193.000002? Si es así, podría ayudar a restar de 193.

3

Puesto que todas las otras respuestas sólo se mencionan el enfoque global pyplot.xscale("log"): También puede configurarlo por eje, pero la sintaxis es:

ax.set_yscale("log") 
Cuestiones relacionadas