为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 x 轴上绘制所有值

如何在 x 轴上绘制所有值

慕尼黑5688855 2023-10-18 16:10:04
这是数据data = {'date': {0: pd.Timestamp('2019-01-31 00:00:00'), 1: pd.Timestamp('2019-02-28 00:00:00'), 2: pd.Timestamp('2019-03-31 00:00:00'), 3: pd.Timestamp('2019-04-30 00:00:00'), 4: pd.Timestamp('2019-05-31 00:00:00'), 5: pd.Timestamp('2019-06-30 00:00:00'), 6: pd.Timestamp('2019-07-31 00:00:00'), 7: pd.Timestamp('2019-08-31 00:00:00'), 8: pd.Timestamp('2019-09-30 00:00:00'), 9: pd.Timestamp('2019-10-31 00:00:00'), 10: pd.Timestamp('2019-11-30 00:00:00'), 11: pd.Timestamp('2019-12-31 00:00:00'), 12: pd.Timestamp('2020-01-31 00:00:00'), 13: pd.Timestamp('2020-02-29 00:00:00'), 14: pd.Timestamp('2020-03-31 00:00:00'), 15: pd.Timestamp('2020-04-30 00:00:00'), 16: pd.Timestamp('2020-05-31 00:00:00'), 17: pd.Timestamp('2020-06-30 00:00:00'), 18: pd.Timestamp('2020-07-31 00:00:00')},        'rate': {0: 100.0, 1: 98.1580633244672, 2: 102.03029115707123, 3: 107.12429902683576, 4: 112.60187555657997, 5: 108.10306860500229, 6: 105.35473845070196, 7: 105.13286204895526, 8: 106.11760178061557, 9: 107.76819930852, 10: 106.77041938461862, 11: 108.84840098309556, 12: 110.29751856107903, 13: 112.93762886874026, 14: 118.04947620270883, 15: 127.80912766377679, 16: 128.90556903738158, 17: 126.96768455091889, 18: 127.95060601426769},        'datelabel': {0: 'Jan 19', 1: 'Feb 19', 2: 'Mar 19', 3: 'Apr 19', 4: 'May 19', 5: 'Jun 19', 6: 'Jul 19', 7: 'Aug 19', 8: 'Sep 19', 9: 'Oct 19', 10: 'Nov 19', 11: 'Dec 19', 12: 'Jan 20', 13: 'Feb 20', 14: 'Mar 20', 15: 'Apr 20', 16: 'May 20', 17: 'Jun 20', 18: 'Jul 20'}}cdf = pd.DataFrame(data)当我绘制它时,它在 x 轴上显示相隔 3 个月的数据我需要显示 x 轴上的所有点。从1月19日开始2月19日...2020年10月。我该如何解决?我就是这样做的g = sns.lineplot('date', 'rate', data=cdf,marker="o")# g.set_xticks(range(0,19))# <--- set the ticks first# g.set_xticklabels(['2011','2012','2013','2014','2015','2016','2017','2018'])g.set_xticklabels(cdf.datelabel, rotation=90)plt.tight_layout()plt.show()我尝试先设置 xticks,然后向其添加值,但它不起作用。
查看完整描述

1 回答

?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

不如将其与datelabel您已有的进行比较:

g = sns.lineplot('datelabel', 'rate', data=cdf, sort=False, marker="o")
g.set_xticklabels(cdf['datelabel'].values, rotation=90)

输出:

https://img1.sycdn.imooc.com/652f932800018cd603900289.jpg

查看完整回答
反对 回复 2023-10-18
  • 1 回答
  • 0 关注
  • 55 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信