Matplotlib 使用特定的x轴值绘制图形

Matplotlib 使用特定的x轴值绘制图形,matplotlib,Matplotlib,我已经用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

我已经用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

谢谢。

我想您希望程序能够识别
日期列的
日期时间
格式。为加载调用提供
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, :]

如果您需要特定日期的特定标签,您必须读入和

请提供一些示例数据和预期输出。否则,很难猜出你到底想要什么。请提供一份清单。