Python 在一个图中叠加两个密度
我有下面的函数,用于绘制a_位置的密度。现在,我想添加b_位置,该位置与a_位置重叠,并带有渐变色。如何使用以下功能在一个图中叠加a_位置和b_位置Python 在一个图中叠加两个密度,python,pandas,matplotlib,Python,Pandas,Matplotlib,我有下面的函数,用于绘制a_位置的密度。现在,我想添加b_位置,该位置与a_位置重叠,并带有渐变色。如何使用以下功能在一个图中叠加a_位置和b_位置 def plot_density(a_positions, b_positions, chr_name, chr_len, out_fname): d = pd.DataFrame(a_positions) d.hist(bins=100) ax = plt.gca() ax.set_xlabel(chr_name
def plot_density(a_positions, b_positions, chr_name, chr_len, out_fname):
d = pd.DataFrame(a_positions)
d.hist(bins=100)
ax = plt.gca()
ax.set_xlabel(chr_name + " positions")
ax.set_ylabel("Density")
ax.set_title('', color='black')
#plt.subplots_adjust(bottom=.25, left=.25)
plt.ticklabel_format(style='plain')
ax.set_xlim(xmin=1, xmax=chr_len)
ax.set_xticks(pd.np.linspace(1, chr_len, 5))
plt.savefig(out_fname)
plt.close()
DataFrame.hist
接受控制透明度的alpha
关键字。那么,如果您将b_位置的alpha
设置为为什么有3种颜色而不是2种?
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.rand(100))
df2 = pd.DataFrame(np.random.rand(100))
df1.hist(bins=10,color='b')
df2.hist(bins=10,ax=plt.gca(),alpha=0.5,color='r')
plt.show()