2017-06-04 5 views
1

私はストレスをプロットしようとすると問題が発生しました。matplotlib tricontourf ploblemもっとデータポイントを与えるとき

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.tri as mtri 
import matplotlib.cm as cm 

def plot(x_plot, y_plot, a_plot): 
    x = np.array(x_plot) 
    y = np.array(y_plot) 
    a = np.array(a_plot) 

    triang = mtri.Triangulation(x, y) 
    refiner = mtri.UniformTriRefiner(triang) 
    tri_refi, z_test_refi = refiner.refine_field(a, subdiv=4) 

    plt.figure(figsize=(18, 9)) 
    plt.gca().set_aspect('equal') 
    #  levels = np.arange(23.4, 23.7, 0.025) 
    levels = np.linspace(a.min(), a.max(), num=1000) 
    cmap = cm.get_cmap(name='jet') 
    plt.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap) 
    plt.scatter(x, y, c=a, cmap=cmap) 
    plt.colorbar() 

    plt.title('stress plot') 
    plt.show() 

まず、私は唯一の8点を使用してプロットを持っている:

x = [2.3384750000000003, 3.671702, 0.3356813, 3.325298666666667, 2.660479, 1.3271675666666667, 1.6680919666666665, 0.6659845666666667] 
y = [0.614176, 0.5590579999999999, 0.663329, 0.24002166666666666, 0.26821433333333333, 0.31229233333333334, 0.6367503333333334, 0.3250663333333333] 
a = [2.572, 0.8214, 5.689, -0.8214, -2.572, -4.292, 4.292, -5.689] 
plot(x, y, a) 

version a

それから私は、長方形のバウンドの情報を提供しよう:

x = [2.3384750000000003, 1.983549, 3.018193, 2.013683, 3.671702, 3.978008, 4.018905, 0.3356813, 0.0, 0.0, 1.0070439, 3.325298666666667, 2.979695, 2.660479, 1.3271675666666667, 0.9909098, 1.6680919666666665, 0.6659845666666667] 
y = [0.614176, -0.038322, 0.922264, 0.958586, 0.5590579999999999, -0.1229, 0.87781, 0.663329, 1.0, 0.0, 0.989987, 0.24002166666666666, -0.079299, 0.26821433333333333, 0.31229233333333334, -0.014787999999999999, 0.6367503333333334, 0.3250663333333333] 
a = [2.572, 2.572, 2.572, 2.572, 0.8214, 0.8214, 0.8214, 5.689, 5.689, 5.689, 5.689, -0.8214, -0.8214, -2.572, -4.292, -4.292, 4.292, -5.689] 
plot(x, y, a) 

version b

私はそれを修正する方法とこれがなぜ起こるのかわかりません。 私が欲しいの図は、次のとおりです。

photoshoped version

私は2番目の図の各点の散布図を行う必要があり、そこに正しいですが、色は輪郭がない理由。

ありがとうございました。

答えて

1

何らかの理由により、UniformTriRefinerによって返されたフィールドは、追加ポイントの場合にはうまく補間されません。その代わりに、元の点の20倍までの値で新しい最小値と最大値を導入します。

理由はわかりませんが、下のプロットは何が起こっているかを示しています。この問題が解消されない場合は、補間方法を選択することができます。

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.tri as mtri 
import matplotlib.cm as cm 

def plot(x_plot, y_plot, a_plot, ax=None): 
    if ax == None: ax = plt.gca() 
    x = np.array(x_plot) 
    y = np.array(y_plot) 
    a = np.array(a_plot) 

    triang = mtri.Triangulation(x, y) 
    refiner = mtri.UniformTriRefiner(triang) 
    tri_refi, z_test_refi = refiner.refine_field(a, subdiv=2) 

    levels = np.linspace(z_test_refi.min(), z_test_refi.max(), num=100) 
    cmap = cm.get_cmap(name='jet') 

    tric = ax.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap) 
    ax.scatter(x, y, c=a, cmap=cmap, vmin= z_test_refi.min(),vmax= z_test_refi.max()) 
    fig.colorbar(tric, ax=ax) 

    ax.set_title('stress plot') 

fig, (ax, ax2) = plt.subplots(nrows=2, sharey=True,sharex=True, subplot_kw={"aspect":"equal"}) 

x = [2.3384750000000003, 3.671702, 0.3356813, 3.325298666666667, 2.660479, 1.3271675666666667, 1.6680919666666665, 0.6659845666666667] 
y = [0.614176, 0.5590579999999999, 0.663329, 0.24002166666666666, 0.26821433333333333, 0.31229233333333334, 0.6367503333333334, 0.3250663333333333] 
a = [2.572, 0.8214, 5.689, -0.8214, -2.572, -4.292, 4.292, -5.689] 
plot(x, y, a, ax) 


x = [2.3384750000000003, 1.983549, 3.018193, 2.013683, 3.671702, 3.978008, 4.018905, 0.3356813, 0.0, 0.0, 1.0070439, 3.325298666666667, 2.979695, 2.660479, 1.3271675666666667, 0.9909098, 1.6680919666666665, 0.6659845666666667] 
y = [0.614176, -0.038322, 0.922264, 0.958586, 0.5590579999999999, -0.1229, 0.87781, 0.663329, 1.0, 0.0, 0.989987, 0.24002166666666666, -0.079299, 0.26821433333333333, 0.31229233333333334, -0.014787999999999999, 0.6367503333333334, 0.3250663333333333] 
a = [2.572, 2.572, 2.572, 2.572, 0.8214, 0.8214, 0.8214, 5.689, 5.689, 5.689, 5.689, -0.8214, -0.8214, -2.572, -4.292, -4.292, 4.292, -5.689] 
plot(x, y, a, ax2) 

plt.show() 

enter image description here

関連する問題