前提・実現したいこと
Pythonのseabornでヒートマップを6枚作成し並べています.
ヒートマップの作成や6枚並べるところまではできたのですが,これに加えて
①x軸とy軸(ここではvx軸とvy軸となっていますが)に波線を入れるとともに,
②それぞれの軸の目盛りが0を含むように(例えば以下の図の場合,x軸の目盛りが-100,-89,...,-1,10,...となっており0が飛ばされていて困っています)したいです.
補助線をペイントツールなどで手動で添えるのはあまりに不格好なので方法を教えてください.
下のコードを実行するためのサンプルcsvはこちらになりますoutputxy0.csv
よろしくお願いします.
該当のソースコード
Python
1import seaborn as sns 2import pandas as pd 3import numpy as np 4import matplotlib.pyplot as plt 5import matplotlib.patches as patches 6 7fig, axes = plt.subplots(2,3, figsize=(15,10), sharex=True, sharey=True) 8data0= pd.read_csv('outputxy0.csv', index_col = 0) 9data1= pd.read_csv('outputxy0.csv', index_col = 0)#質問をシンプルにするために6枚の読み取りcsvファイルを全て同じにしてあります. 10data2= pd.read_csv('outputxy0.csv', index_col = 0) 11data3= pd.read_csv('outputxy0.csv', index_col = 0) 12data4= pd.read_csv('outputxy0.csv', index_col = 0) 13data5= pd.read_csv('outputxy0.csv', index_col = 0) 14sns.heatmap(data0, ax = axes[0,0], cmap = 'CMRmap_r'); 15axes[0,0].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=0(ns)') 16c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 17axes[0,0].add_patch(c) 18sns.heatmap(data1, ax = axes[0,1], cmap = 'CMRmap_r'); 19axes[0,1].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=1(ns)') 20c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 21axes[0,1].add_patch(c) 22sns.heatmap(data2, ax = axes[0,2], cmap = 'CMRmap_r'); 23axes[0,2].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=2(ns)') 24c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 25axes[0,2].add_patch(c) 26sns.heatmap(data3, ax = axes[1,0], cmap = 'CMRmap_r'); 27axes[1,0].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=3(ns)') 28c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 29axes[1,0].add_patch(c) 30sns.heatmap(data4, ax = axes[1,1], cmap = 'CMRmap_r'); 31axes[1,1].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=4(ns)') 32c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 33axes[1,1].add_patch(c) 34sns.heatmap(data5, ax = axes[1,2], cmap = 'CMRmap_r'); 35axes[1,2].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=5(ns)') 36c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 37axes[1,2].add_patch(c)
試したこと
①xmin,xmaxを設定して各画像のc=patches.Circle~のすぐ下の行に加えていくやり方は最後の(右下の)画像にしか反映されませんでした.
plt.hlines(0,xmin, xmax, "blue", linestyle="dashed")
②0を含む方法についてはそれらしき記事に到達さえできませんでした.
失敗例
添付コード途中を以下に変更
sns.heatmap(data1, ax = axes[0,1], cmap = 'CMRmap_r');
axes[0,1].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=1(ns)')
c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed')
axes[0,1].add_patch(c)
plt.plot([-10, 10], [0, 0])
失敗例2
Python
1import seaborn as sns 2import pandas as pd 3import numpy as np 4import matplotlib.pyplot as plt 5import matplotlib.patches as patches 6 7fig, axes = plt.subplots(2,3, figsize=(15,10), sharex=True, sharey=True) 8data0= pd.read_csv('outputxy0.csv', index_col = 0) 9data1= pd.read_csv('outputxy0.csv', index_col = 0) 10data2= pd.read_csv('outputxy0.csv', index_col = 0) 11data3= pd.read_csv('outputxy0.csv', index_col = 0) 12data4= pd.read_csv('outputxy0.csv', index_col = 0) 13data5= pd.read_csv('outputxy0.csv', index_col = 0) 14sns.heatmap(data0, ax = axes[0,0], cmap = 'CMRmap_r'); 15axes[0,0].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=0(ns)') 16c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 17axes[0,0].add_patch(c) 18y = (plt.yticks()[0][0] + plt.yticks()[0][-1]) / 2 19plt.axhline(y=y, linewidth=2, color="r") 20sns.heatmap(data1, ax = axes[0,1], cmap = 'CMRmap_r'); 21axes[0,1].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=1(ns)') 22c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 23axes[0,1].add_patch(c) 24sns.heatmap(data2, ax = axes[0,2], cmap = 'CMRmap_r'); 25axes[0,2].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=2(ns)') 26c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 27axes[0,2].add_patch(c) 28y = (plt.yticks()[0][0] + plt.yticks()[0][-1]) / 2 29plt.axhline(y=y, linewidth=2, color="r") 30sns.heatmap(data3, ax = axes[1,0], cmap = 'CMRmap_r'); 31axes[1,0].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=3(ns)') 32c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 33axes[1,0].add_patch(c) 34sns.heatmap(data4, ax = axes[1,1], cmap = 'CMRmap_r'); 35axes[1,1].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=4(ns)') 36c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 37axes[1,1].add_patch(c) 38sns.heatmap(data5, ax = axes[1,2], cmap = 'CMRmap_r'); 39axes[1,2].set(xlabel = 'vx(10^6m/s)', ylabel = 'vy(10^6m/s)', title = 't=5(ns)') 40c = patches.Circle(xy = (100, 100), radius = 50, ec = 'r', fill = False,linestyle='dashed') 41axes[1,2].add_patch(c)
補足情報(FW/ツールのバージョンなど)
Python,Anacondaは質問直前に最新のバージョンにしました.
回答1件
あなたの回答
tips
プレビュー