2016-11-19 15 views
0

私は障壁を通っているソリトンについてのプログラムに取り組んでおり、実際にはレンガで作られているように見えるようにしようとしています。問題は、「レンガ」テクスチャをプロットする方法が見つからないことです。私はfill_between()を使用しますが、レンガを許可する別のオプションがある場合は、使用することで問題はありません。matplotlibのレンガ壁

私のコードは次のとおり十分にそのように定義され、すべてのアレイと

gs=GridSpec(8,1) #7 rows and 1 column 
state=self.fig.add_subplot(gs[2:,:]) 
light=self.fig.add_subplot(gs[0:2,:]) 
state.set_xlabel("Position ($x/ \\xi$)") 
state.set_ylabel("Density $|\psi|^2 \\xi$") 
state.plot(posit,phi2) 
state.fill_between(posit,phi2,0,facecolor='0.80') 
potential=state.twinx() 
potential.plot(posit,pote,'g') 

。プログラムを実行するときにコードに問題はありませんが、可能であればレンガを描く方法を知りたいと思います。

実際の状況の画像を添付します。レンガを使用してビルドするのを待っている間、バリアは空になっています。

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

Image of the plot

+1

にレンガの壁を配置する方法についての例だろう... [この例]( http://matplotlib.org/examples/pylab_examples/demo_annotation_box.html#pylab-examples-example-code-demo-annotation-box-py)は、プロット上に配置されたイメージを表示します。 – wwii

答えて

3

これは、あなたが適切な画像を見つけることができる場合は、画像

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.patches 

f = lambda x, x0, sig: np.exp(-(x-x0)**2/sig**2) 

x = np.linspace(0,10, 301) 
pulse = f(x, 2, 0.5)*2.8 


fig, ax = plt.subplots(figsize=(10,4)) 

image = plt.imread("brick_texture104.png") 
#http://p78i.imgup.net/brick_textadf0.png 
im = ax.imshow(image, extent=[4,4+512./256,0,933./256]) # image is 512 x 933, 
ax.set_aspect("equal") 
ax.plot(x, pulse, color="r", alpha = 0.7, lw=4) 

wall_patch = matplotlib.patches.Rectangle((4.5,0),1,3, transform=ax.transData) 
im.set_clip_path(wall_patch) 

ax.set_ylim([0,4]) 
ax.set_xlim([0,10]) 
plt.show() 

enter image description here

+0

ありがとう!それは完璧に働いた!そして、今よりもっと良く見えます! – Nana20

関連する問題