Python 3.x 在seaborn中合并条形图和线形图

Python 3.x 在seaborn中合并条形图和线形图,python-3.x,bar-chart,seaborn,linechart,Python 3.x,Bar Chart,Seaborn,Linechart,我试图结合两个不同的图,一个是条形图,另一个是直线图 我有以下代码: plt.figure(figsize=(30, 7)) # Plot 1: Line chart for loan distribution over years plt.subplot(1, 4, 1) cx = loan_data.groupby('issue_d_year').loan_amnt.count().plot(kind='line', fontsize=7) for p in cx.patches:

我试图结合两个不同的图,一个是条形图,另一个是直线图

我有以下代码:

plt.figure(figsize=(30, 7))

# Plot 1: Line chart for loan distribution over years
plt.subplot(1, 4, 1)
cx = loan_data.groupby('issue_d_year').loan_amnt.count().plot(kind='line', fontsize=7)
for p in cx.patches:
    cx.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.title("Number of Loans over years", weight ='bold')
plt.ylabel("Count of loan amount")
plt.xlabel("Loans funded across years")


# Plot 2: bar chart for loan distribution over years
plt.subplot(1, 4, 2)
cxs = loan_data.groupby('issue_d_year').loan_amnt.count().plot(kind='bar', fontsize=7)
for p in cxs.patches:
    cxs.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.title("Number of Loans over years", weight ='bold')
plt.ylabel("Count of loan amount")
plt.xlabel("Loans funded across years")

plt.figure(figsize=(70, 7))

# Plot 3: Line chart for loan distribution over months
plt.subplot(1, 4, 3)
dx = loan_data.groupby('issue_d_month').loan_amnt.count().plot(kind='line', fontsize=7)
for p in dx.patches:
    dx.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.title("Number of Loans over months", weight ='bold')
plt.ylabel("Count of loan amount")
plt.xlabel("Loans funded across months")


# Plot 4: Bar chart for loan distribution over months
plt.subplot(1, 4, 4)
dxs = loan_data.groupby('issue_d_month').loan_amnt.count().plot(kind='bar', fontsize=7)
for p in dxs.patches:
    dxs.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
plt.title("Number of Loans over months", weight ='bold')
plt.ylabel("Count of loan amount")
plt.xlabel("Loans funded across months")
plt.show()
输出:


有没有办法将前两张图表合并为一张,将下两张图表合并为一张,并将线条涂成红色

熊猫的条形图始终使用分类x轴。线图使用数字x轴。将年份转换为字符串将使用分类x轴绘制两个图。例如
loan_data['issue_d_year']=loan_data['issue_d_year'].aType(str)
Pandas'条形图始终使用分类x轴。线图使用数字x轴。将年份转换为字符串将使用分类x轴绘制两个图。例如
loan_data['issue_d_year']=loan_data['issue_d_year']。astype(str)