also ich habe erst vor kurzem begonnen mich mit Python zu beschäftigen und stehe nun vor einem kleinen Problem, das doch ein wenig größer zu sein scheint. Ich habe von den Aufenthaltsorten eines Teilchens zu verschiedenen Zeitpunkten, die Aufenthaltswahrscheinlichkeitsdichte mittels KDE berechnet. Diese Werte sind so gering, dass sie nicht signifikant durch 4 Nullstellen dargestellt werden können, was aber der Standard beim Contour plot zu sein scheint. Ich würde daher gerne irgendwie die Anzeige der Zahlen so modifizieren, dass ich eine wissenschaftliche Notation verwenden kann, also 4,56 * 10^(-6) zum Beispiel.
Ich habe es schon mit der Option
Code: Alles auswählen
fmt = ticker.LogFormatterMathtext()
Hier einmal mein Ausgangscode:
Code: Alles auswählen
import numpy as np
import matplotlib.pyplot as pl
import scipy.stats as st
from matplotlib.patches import Ellipse
import matplotlib.ticker as ticker
data = np.loadtxt(filename)
x = data[:, 0]
y = data[:, 1]
xmin, xmax = 265, 675
ymin, ymax = 45,450
# Set Parameters from Autotracking
a1 = 277
a2 = 664
b1 = 51
b2 = 437
a = (a2-a1)
b = (b2-b1)
xm = a1+(a/2)
ym = b1+(b/2)
# Peform the kernel density estimate
xx, yy = np.mgrid[xmin:xmax:200j, ymin:ymax:200j]
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = st.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)
fig = pl.figure()
ax = fig.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
# Contourf plot
cfset = ax.contourf(xx, yy, f, cmap='Blues')
cset = ax.contour(xx, yy, f, colors='k')
# Label plot
ax.clabel(cset, inline=1, fontsize=10)
ax.set_xlabel('Bewegung in $x$-Richtung [px]')
ax.set_ylabel('Bewegung in $y$-Richtung [px]')
# Plot ellipse as border of system
ellipse = Ellipse(xy=(xm, ym), width=a, height=b,
edgecolor='black', fc='None', lw=1.5)
pl.gca().add_patch(ellipse)
pl.gca().set_aspect('equal', adjustable='box')
pl.show()