あなたが探しているものを行う方法についてのアイデアを得る可能性があります:
import pandas as pd
import matplotlib.pyplot as plt
index = ["D1_1-2", "D1_2-3", "D1_3-4"]
df1 = pd.DataFrame({"count": [10, 20, 25]}, index=index)
df2 = pd.DataFrame({"count": [15, 11, 30]}, index=index)
ax = df1.plot(style='ro', legend=False)
df2.plot(style='bo',ax=ax, legend=False)
plt.show()
キーがdf1
のプロットから軸を使用するdf2
のプロットを求めています。次のようにあなたがこのために得る
プロットである:ジッタと
Aproach:あなたのデータに一つのアプローチを、ジッタを追加したい場合は、次のよう
をすることができ、代わりに使用しての前のプロットの軸は、我々はデータフレームを連結し、それを反復:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
index = ["D1_1-2", "D1_2-3", "D1_3-4", "D1_4-5", "D1_5-6", "D1_6-7", "D1_7-8", "D1_8-9", "D1_1-3", "D1_2-3", "D1_3-5", "D1_5-7"]
df1 = pd.DataFrame({"count": [10, 20, 25, 30, 32, 35, 25, 15, 5, 17, 11, 2]}, index=index)
df2 = pd.DataFrame({"count": [15, 11, 30, 30, 20, 30, 25, 27, 5, 16, 11, 5]}, index=index)
#We ensure we use different column names for df1 and df2
df1.columns = ["count1"]
df2.columns = ["count2"]
#We concatenate the dataframes
df = pd.concat([df1, df2],axis=1)
#Function to add jitter to the array
def rand_jitter(arr):
stdev = .01*(max(arr)-min(arr))
return arr + np.random.randn(len(arr)) * stdev
# We iterate between the two columns of the concatenated dataframe
for i,d in enumerate(df):
y = df[d]
arr = range(1,len(y)+1)
x = rand_jitter(arr)
plt.plot(x, y, mfc = ["red","blue"][i], mec='k', ms=7, marker="o", linestyle="None")
# We set the ticks as the index labels and rotate the labels to avoid overlapping
plt.xticks(arr, index, rotation='vertical')
plt.show()
を最後に、これは、以下のグラフに結果:
あなたはy軸でどの変数を期待していますか?元のデータから期待される出力を表示できますか? –
予想される出力の画像を追加しました.Y軸は動的数値を持ちます。例えば:入力データD1_1_2に基づくラベルは、Y軸上に示された39736,0.01.37などの値を有する。 –