2016-04-30 31 views
4

私はこれと同様のグラフ(出典:http://www.scminc.com/resources/SCM_TIPSTRICKS_Petrel_Well_Sections_2013_July14.pdf):用の塗りつぶしの色を作成するためにはPython/matplotlibの/パンダに方法を探しています値に基づいたカラー塗りつぶし?

enter image description here

それは塗りのカラーマップを使用しています(左画像のx軸上の特定の間隔に基づいて、色を割り当てます。残念ながら、私は解決策を見いだすことはできませんでした。一般的にPythonを初めて熟知して以来、私はそれを行う方法を見つけることができません。

感謝

+1

がうまく、あなたは絶対にあなたが使用できる色の範囲を持っている必要はありません場合は、[fill_between] (http://matplotlib.org/examples/pylab_examples/fill_between_demo.html)。そうでなければ、[パッチコレクション](http://matplotlib.org/examples/api/patch_collection.html)のようなものが必要かもしれません。また、四角いイメージを作成し、それを[clipping](http://matplotlib.org/examples/images_contours_and_fields/image_demo_clip_path.html)とパッチを付けて検討することもできます。 –

+0

..前のコメントを続ける...最後のオプションは、[Polygon patch](http://matplotlib.org/api/patches_api.html#matplotlib.patches.Polygon)を使う必要があります。 –

+0

'pcolor'もこれに対応しているかもしれません。 – tacaswell

答えて

0

あなたはそれをクリップし、その後、imshowを背景として塗りつぶしをプロットすることができます。 fill_betweenxを使用してマスクを作成できます。ここで

がランダムなデータを使用した例です:

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

# Make a random x and a y to go with it. 
np.random.seed(26) 
x = np.random.normal(0, 1, 200).cumsum() 
y = np.arange(x.size) 

# Set up the figure. 
fig, ax = plt.subplots(figsize=(2, 10)) 

# Make the background 'image'. 
im = ax.imshow(x.reshape(-1, 1), 
       aspect='auto', 
       origin='lower', 
       extent=[x.min(), x.max(), y.min(), y.max()] 
      ) 

# Draw the path. 
paths = ax.fill_betweenx(y, x, x.min(), 
         facecolor='none', 
         lw=2, 
         edgecolor='b', 
         ) 

# Make the 'fill' mask and clip the background image with it. 
patch = PathPatch(paths._paths[0], visible=False) 
ax.add_artist(patch) 
im.set_clip_path(patch) 

# Finish up. 
ax.invert_yaxis() 
plt.show() 

この利回り:

some random data filled with colour

関連する問題