У меня есть фигура, которая не показывает правильные даты на оси X. Возможно, потому что есть слишком много наблюдений, чтобы показать, и это приводит к тому, что не показывает никаких. Я не уверен, стоит ли мне использовать функцию set_xticks
, но она дает мне атрибут error
AttributeError: модуль 'matplotlib.pyplot' не имеет атрибута 'set_xticks'
Мой текущий код такой:
def plot_w(dataframe,ticker,benchmark):
# a. Printing highest observed values and corresponding date
max1 = data_df.loc[:, ticker].max()
max2 = data_df.loc[:, benchmark].max()
max1_date = data_df[data_df[ticker] == max1]['Date'].values[0]
max2_date = data_df[data_df[benchmark] == max2]['Date'].values[0]
print("The highest adjusted close price observed at: \n", ticker, ":", max1.round(2), "USD on the date ", max1_date,
"\n", benchmark, ":", max2.round(2), "USD on the date", max2_date)
# b. Setting up plot based on dropdown input
I = data_df.columns == ticker
mpl_figure = dataframe.loc[:, ['Date',ticker,benchmark]]
mpl_figure.plot(x='Date', y=[ticker,benchmark], style=['-b','-k'], figsize=(10, 5), fontsize=11, legend='true', linestyle = '-')
plt.ylabel("USD",labelpad=5)
plt.locator_params(axis='x', nbins=20)
title = "Adjusted close prices for " + ticker + " and " + benchmark
plt.title(title)
plt.set_xticks(data_df['Date'].values) # Code fails here
# c. Creating the widget for the plot
widgets.interact(plot_w,
dataframe = widgets.fixed(data_df),
ticker = widgets.Dropdown(
options=data_df.columns,
value='ATVI',
description='Company 1:',
disabled=False,
),
benchmark = widgets.Dropdown(
options=data_df.columns,
value='AAPL',
description='Company 2:',
disabled=False,
)
)
Фигура выглядит так:
