我是Python的新手,特别是Matplotlib,但我想更改等值线图中有效数字的数量,或者最好将符号更改为科学。 我发现这样,参考Matlab:http://de.mathworks.com/matlabcentral/newsreader/view_thread/33019
有没有机会这样做?另外,我想改变轴的背景。所以只有轮廓区域以不同的蓝色调着色。这可能。
这是我的代码:
import numpy as np
import matplotlib.pyplot as pl
import scipy.stats as st
from matplotlib.patches import Ellipse
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, format='%.4f')
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()
这是我的输出: Graph
答案 0 :(得分:0)
在尝试按照示例的说明后,我想出了这样的事情: Graph2 但这并不是我想要的。我只想改变轮廓线的符号,因为内核的命运如此之小(例如约为0,0000334)。所以有两种可能的方式: 1)将其改为科学记数法:3,34 * 10 ^( - 5)(首选方式) 2)扩大要显示的有效数字量
到目前为止我的代码:
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', locator=pl.LogLocator())
# Label plot
fmt = ticker.LogFormatterMathtext()
fmt.create_dummy_axis()
ax.clabel(cset, inline=1, fontsize=10, fmt=fmt)
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()
感谢您的帮助!