2012-04-02 14 views
5

Ich habe vales mit sehr kleinen Unterschied wie ... 0.000001. Ich möchte sie auf logarithmischer Skala visualisieren. Ich frage mich, wie man es in Matplotlib macht.Wie visualisiert man Werte in logarithmischer Skala auf Matplotalib?

Vielen Dank

+0

Mögliches Duplikat von [ Zeichnen Sie logarithmische Achsen mit Matplotlib in Python] (http://stackoverflow.com/questions/773814/plot-logarithmic-axes-with-matplotlib-in-python) – bluenote10

Antwort

15

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

Fügen Sie einfach das Stichwort Argument log=True

Oder in einem Beispiel:

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

Sie dieses Stück verwenden können Code:

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

Statt plot können Sie semilogy verwenden:

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() 

Aber ich bin mir nicht ganz sicher, was Sie von der Verwendung einer logarithmischen Skala zu gewinnen hoffen. Wenn Sie "kleine Differenz" sagen, meinen Sie, dass die Werte etwa 193.000001 und 193.000002 sein könnten? Wenn ja, könnte es helfen, 193.

3

abzuziehen off Da alle anderen Antworten nur den globalen pyplot.xscale("log") Ansatz erwähnen: Sie können es auch pro Achse, aber dann ist die Syntax:

ax.set_yscale("log") 
Verwandte Themen