[问题] DataFrame画图跑歪怎么修正

楼主: wrhgpw (绿茶)   2022-09-12 08:25:26
大家安安
想请问 dataframe plot 的时候时间轴莫名偏移到非选定区域
https://imgur.com/lPpy417
想要在选定的日期后面加上颜色,另外想让文字对齐x轴的点点,像这样
https://imgur.com/EGartVm
https://imgur.com/XcRCWBl
https://imgur.com/Cl86iyz
1. 已经确认有设为 index,且为datetime
2. 表格为 pd.DataFrame 型态
求解 感恩
作者: KSJ (阿真)   2022-09-12 09:20:00
https://bit.ly/3L4VOuW datetime64的Series不会自动处理
作者: lycantrope (阿宽)   2022-09-12 13:27:00
x不是stock["Close"]而是stock.index.valueswhere没问题,想要画曲线下y2可以给stock["Close"]看太懂,文字想要怎样对齐,可以画清楚一点比较好帮
作者: karco (karco)   2022-09-12 16:13:00
对齐的话可以在set_ticklabels时,指定ha = 'center'ax.xaxis.set_ticklabels([label_name, ...],ha ='center')
作者: lycantrope (阿宽)   2022-09-12 16:53:00
作者: karco (karco)   2022-09-12 16:59:00
每10年一次的话,可以用filter的方式?或是你是指显示出来的ticks数目,那个应该可以在ticks调整筛选的话就new_df = df[df['year']%10==0]之类的设定一些条件去筛选数据点
作者: lycantrope (阿宽)   2022-09-12 17:11:00
matplotlib.dates有locator跟formatter可以用https://matplotlib.org/stable/api/dates_api.html

Links booklink

Contact Us: admin [ a t ] ucptt.com