绘制具有特定x轴值的图形

问题描述 投票:-2回答:1

我使用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

谢谢。

matplotlib
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, :]

如果您想要特定日期的特定标签,您必须阅读axesdate formatters

© www.soinside.com 2019 - 2024. All rights reserved.