import pandas as pd
import numpy as np
import matplotlib
matplotlib.use('nbagg')
import matplotlib.pyplot as plt
from matplotlib import rcParams
from IPython.core.display import display, HTML
def convert_to_unix(s):
return time.mktime(datetime.datetime.strptime(s,"%m/%d/%Y %H:%M").timetuple())
def return_with_trip_times(month):
duration = month[['tpep_pickup_datetime','tpep_dropoff_datetime']]
duration_pickup = [convert_to_unix(x) for x in duration['tpep_pickup_datetime'].astype(str).values]
duration_drop = [convert_to_unix(x) for x in duration['tpep_dropoff_datetime'].astype(str).values]
durations = (np.array(duration_drop) - np.array(duration_pickup))/float(60)
new_frame = month[['passenger_count','trip_distance','pickup_longitude','pickup_latitude','dropoff_longitude','dropoff_latitude','total_amount']]
new_frame['trip_times'] = durations
new_frame['pickup_times'] = duration_pickup
new_frame['Speed'] = 60*(new_frame['trip_distance']/new_frame['trip_times'])
return new_frame
frame_with_durations = return_with_trip_times(month)
sns.boxplot(y="trip_times", data =frame_with_durations)
plt.show()
这将结果显示为
<IPython.core.display.Javascript object>
<IPython.core.display.HTML object>
,即使将图形首选项设置为自动,我也无法通过它查看图形。我该怎么办才能查看图表?