-2

我已经使用我在 excel 上的数据绘制了一个图表,并且有 x 和 y 轴的值。但是,我想通过仅显示仅反映轴上关键日期的特定值来更改 x 轴上的值。那可能吗?

这是我写的代码:

import pandas as pd 
from matplotlib import pyplot as plt #download matplot library
#create a graph of the cryptocurrencies in excel

btc = pd.read_excel('/Users/User/Desktop/bitcoin_prices.xlsx') 
btc.set_index('Date', inplace=True) #Chart Fit
btc.plot()
plt.xlabel('Date', fontsize= 12)
plt.ylabel('Price ($)', fontsize= 12)
plt.title('Cryptocurrency Prices', fontsize=15)
plt.figure(figsize=(60,40))
plt.show() #plot then show the file

谢谢你。

4

1 回答 1

0

我猜你希望程序能够识别列的datetime格式'Date'。供应parse_dates=['Dates']装载呼叫。然后,您可以为特定日期的数据编制索引。例如:

import datetime as dt
import numpy as np
import pandas as pd

btc = pd.read_csv('my_excel_data.xlsx', parse_dates=['Dates'], index_col='Dates')

selected_time = np.arange(dt.datetime(2015, 1, 1), dt.datetime(2016, 1, 1), dt.timedelta(7))
btc_2015 = btc.loc[selected_time, :]

如果您想要特定日期的特定标签,则必须读取日期格式化程序

于 2019-04-25T20:54:56.203 回答