我使用文件中的数据创建了另一个直方图。现在,我想将这些图组合成一个直方图。下面是生成不同直方图的代码。
import pandas as pd
import matplotlib.pyplot as plt
import collections
import numpy as np
df = pd.read_excel ('C:/Users/rajive/Desktop/Final_code/MSCN1.xlsx')
df1 = pd.read_excel ('C:/Users/rajive/Desktop/Final_code/MSCN2.xlsx')
df2 = pd.read_excel ('C:/Users/rajive/Desktop/Final_code/MSCN3.xlsx')
df3 = pd.read_excel ('C:/Users/rajive/Desktop/Final_code/MSCN4.xlsx')
def calculate_pair_product_coefficients () :
return collections.OrderedDict ({
'mscn1' : df,
'mscn2' : df1,
'mscn3' : df2,
'mscn4' : df3,
# 'mscn1' : mscn_coefficients,
})
def plot_histogram (x, label) :
n, bins = np.histogram (x.ravel (), bins = 100)
n = n / np.max (n)
plt.plot (bins [:-1], n, color = 'green', label = label, marker = 'o')
coefficients = calculate_pair_product_coefficients ()
plt.rcParams ["figure.figsize"] = 12, 11
for name, coeff in coefficients.items () :
plot_histogram (coeff.values.ravel (), name)
plt.axis ([-2, 2, 0, 1.05])
plt.legend ()
plt.show ()