我的问题是,我只能标记我的图的x轴。此外,标签是一个不同的名称,比我定义的代码。此外,当绘制一个网格,它只绘制y轴网格,而不是两者。
这是我要绘制的 Dataframe 的代码
time_field = "thread_created_utc"
thread_field = "thread_id"
columns = [thread_field, time_field] # identify relevant columns
df_threads = df[columns].copy() # subset original dataframe to include only relevant information
df_threads[time_field] = pd.to_datetime(df_threads[time_field]) # Convert the time column to a datetime object
time_gran = "H" # time granularity: use H if hourly, D if daily
df_threads = (df_threads
.set_index(time_field) # set the timing as the index of the dataframe
.resample(time_gran) # Use resample function to group data by time (e.g., days or hours)
[thread_field] # specify the column we need to aggregate/count
.nunique() # count the number of unique elements within each group
)
df_threads
#Plotting time series, defining what kind of graph, x and y axis labeling, the title, the size #of the graph, the width of the line and colour
df_threads.plot(kind = "line", x = "Time in hours", y = "Number of movies", title = "Number of movies per hour", figsize= (10, 5), linewidth = 1.5, color = "orange")
#Displaying a grid which makes it easier to read the values.
plt.grid(axis = "both", color = "grey", linestyle = "--", linewidth = 0.5)
1条答案
按热度按时间wfauudbj1#
没有数据样本会使故障排除变得困难,但这里有一个你应该做的事情的例子: