df_trips['Start date'] = pd.to_datetime(df_trips['Start date']) df_trips['End date'] = pd.to_datetime(df_trips['End date']) # 用户出行时长分布 df_trips['duration_min'] = df_trips['Total duration (Seconds)'] / 60 df_trips['duration_min'].hist(bins=100, range=[0, 60]) plt.figure(figsize=(10, 6)) sns.histplot(data=df_trips, x='duration_min', kde=False, color='skyblue') plt.title("Trip Duration Distribution") plt.xlabel("Duration (min)",fontsize=12) plt.ylabel("Count",fontsize=12) plt.show()将此代码的背景换为天蓝色
时间: 2024-01-28 20:04:19 浏览: 104
可以在绘制直方图时,指定`color`参数为`'skyblue'`,即可将直方图背景颜色换为天蓝色。修改后的代码如下:
```python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 加载数据集
df_trips = pd.read_csv('trips.csv')
# 将起始时间和结束时间转换为datetime格式
df_trips['Start date'] = pd.to_datetime(df_trips['Start date'])
df_trips['End date'] = pd.to_datetime(df_trips['End date'])
# 计算出行时长(单位:分钟)
df_trips['duration_min'] = df_trips['Total duration (Seconds)'] / 60
# 绘制出行时长分布直方图
plt.figure(figsize=(10, 6))
sns.histplot(data=df_trips, x='duration_min', kde=False, color='skyblue')
plt.title("Trip Duration Distribution")
plt.xlabel("Duration (min)", fontsize=12)
plt.ylabel("Count", fontsize=12)
plt.show()
```
其中,`color='skyblue'`指定了直方图的颜色为天蓝色。
阅读全文
相关推荐











