Python Seaborn Barplot和Lineplot(共享Y轴)不使用其他图形的相同工作代码

Python Seaborn Barplot和Lineplot(共享Y轴)不使用其他图形的相同工作代码,python,pandas,matplotlib,graph,seaborn,Python,Pandas,Matplotlib,Graph,Seaborn,在这个网站的帮助下,我已经能够绘制多种图形类型,但有一个图形无法工作,即使我使用了在另一个图形上工作的相同代码 这是工作代码 fig, ax = plt.subplots(figsize=(15,6)) g = sns.lineplot(x='report_date', y='UTL_R', data=tm_daily_df, ax=ax, hue = 'shift', marker='o', markersize=10) ax2 = ax.twinx() g = s

在这个网站的帮助下,我已经能够绘制多种图形类型,但有一个图形无法工作,即使我使用了在另一个图形上工作的相同代码

这是工作代码

fig, ax = plt.subplots(figsize=(15,6))
g = sns.lineplot(x='report_date',  y='UTL_R', data=tm_daily_df, ax=ax, hue = 'shift',
             marker='o', markersize=10)
ax2 = ax.twinx()
g = sns.barplot(x='report_date',  y='Head_Count', data=tm_daily_df, ax=ax2, hue='shift',alpha=.5)
ax.set_title('--Utilization Ratio-- vs □□HeadCount□□', fontsize = 17)
plt.show()
其中tm_daily_df是该数据

  report_date shift  UTL_R  Head_Count
0      3/31/19     A   1.00          30
1       4/1/19     A   1.05          58
2       4/2/19     A   1.02          64
3       4/3/19     A   1.00          61
4       4/4/19     A   1.00          55
5       4/5/19     A   0.97          53
6       4/6/19     A   1.02          40
7      3/31/19     1   0.97          10
8      3/31/19     2   1.07           3
9      3/31/19     3   1.01           7
10      4/1/19     1   1.10          24
11      4/1/19     2   1.02          14
12      4/1/19     3   1.00          10
13      4/2/19     1   1.04          26
14      4/2/19     2   1.02          18
15      4/2/19     3   0.98          10
16      4/3/19     1   0.95          25
17      4/3/19     2   0.99          16
18      4/3/19     3   1.10          10
19      4/4/19     1   1.05          17
20      4/4/19     2   0.95          15
21      4/4/19     3   1.00          13
22      4/5/19     1   0.94          20
23      4/5/19     2   1.02          15
24      4/5/19     3   0.95           8
25      4/6/19     1   1.07          19
26      4/6/19     2   1.06           9
27      4/6/19     3   0.81           2
提供以下结果:

现在,当我尝试对一组相似的数据做完全相同的处理时 工作时数轮班日分组=

   report_date  shift  999  load_count
0   2019-03-31      1   42       227.0
1   2019-03-31      2   13       141.0
2   2019-03-31      3   79       267.0
3   2019-04-01      1  146       580.0
4   2019-04-01      2  177       627.0
5   2019-04-01      3  127       460.0
6   2019-04-02      1  192       583.0
7   2019-04-02      2  121       626.0
8   2019-04-02      3   98       291.0
9   2019-04-03      1  172       580.0
10  2019-04-03      2   83       372.0
11  2019-04-03      3   78       323.0
12  2019-04-04      1   83       403.0
13  2019-04-04      2   69       340.0
14  2019-04-04      3   86       268.0
15  2019-04-05      1  164       567.0
16  2019-04-05      2  169       593.0
17  2019-04-05      3   48       249.0
18  2019-04-06      1  102       304.0
19  2019-04-06      2   48       246.0
20  2019-04-06      3    4         0.0
它返回以下内容:

请注意日期和缺少线图,但辅助轴在那里。 我已经重新设置了日期格式,消除了空值,但由于某些原因,它甚至没有显示线条图,并且日期以错误的格式显示出来。发生了什么事

同样,以下是工作图代码:

fig, ax = plt.subplots(figsize=(15,6))
g = sns.lineplot(x='report_date',  y='UTL_R', 
data=tm_daily_df, ax=ax, hue = 'shift',
             marker='o', markersize=10)
ax2 = ax.twinx()
g = sns.barplot(x='report_date',  y='Head_Count', data=tm_daily_df, ax=ax2, hue='shift',alpha=.5)
ax.set_title('--Utilization Ratio-- vs □□HeadCount□□', fontsize = 17)
plt.show()
这就是我目前存在的祸根:

fig, ax = plt.subplots(figsize=(15,6))
g = sns.lineplot(x='report_date',  y='999', data=job_hours_df_shiftday_grouped, ax=ax, hue = 'shift',
             marker='o', markersize=10)
ax2 = ax.twinx()
g = sns.barplot(x='report_date',y='load_count', data=job_hours_df_shiftday_grouped, ax=ax2, alpha=.5, 
                hue = 'shift')
ax.set_title('Daily 999 instances by Shift', fontsize = 17)
plt.show()

我不知道为什么第二个图形代码不工作。它来自相同的数据源,使用相同的工作代码。

这两个数据集之间有明显的区别!值不同,但数据类型相同。什么可能会破坏图表。如果我把它们分开做,线形图就像一个符咒,但是一旦添加了条形图,报告日期就会变得很模糊,这样你就可以通过
print(df.info())
来了解列的数据类型。数据类型是相同的,除了当我将其转换为索引时,它会转换为datetimeindex,但在它成为索引之前,它们都是对象。该错误没有意义,至少在第一种(“工作”)情况下绘制的是字符串,在第二种(“非工作”)情况下绘制的是datetime对象。如果您说pandas显示相同的数据类型(object==string),那么转换可能会在seaborn函数内部发生,原因未知。
fig, ax = plt.subplots(figsize=(15,6))
g = sns.lineplot(x='report_date',  y='999', data=job_hours_df_shiftday_grouped, ax=ax, hue = 'shift',
             marker='o', markersize=10)
ax2 = ax.twinx()
g = sns.barplot(x='report_date',y='load_count', data=job_hours_df_shiftday_grouped, ax=ax2, alpha=.5, 
                hue = 'shift')
ax.set_title('Daily 999 instances by Shift', fontsize = 17)
plt.show()