我有一些数据要尝试显示为contourf。例如,我在Y轴上有28个点,在X轴上有57个点,并且在此网格中每个点都有值。
现在,当我打印此图时,由于刻度线在轴上的位置,我的轴标签不可读。
我已经尝试过matplotlib.ticker,但是它什么也没做。假设可以将不包含轮廓f的值的N个元素覆盖的轴改写为M个元素(步长等于0.1)吗?
dat文件是这样的:
0; 0; value
0; 0.1123; value
...
0; n; value
0.1123; 0; value
...
n; n; value
代码:
import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
from matplotlib import cm
import matplotlib.ticker as ticker
with open('file.dat') as content:
zawartosc = [x.strip() for x in content]
#unique coloumn
X = [linijka.split()[0] for linijka in zawartosc]
X = set(X)
X = sorted(X)
print(X)
Y = [linijka.split()[1] for linijka in zawartosc]
Y = set(Y)
Y = sorted(Y)
print(Y)
# 1D into 2D array
F = [linijka.split()[2] for linijka in zawartosc]
F2D = np.reshape(F,( len(X),len(Y)))
F2D = np.transpose(F2D)
print(F2D)
#plot
fig,ax = plt.subplots(figsize=(20, 10))
temp = ax.contourf(X,Y,F2D,500,cmap=cm.inferno,)
plt.xlabel('X')
plt.ylabel('Y')
fig.colorbar(temp)
plt.show()
plt.savefig("temp.png")