python横坐标为时间序列绘制散点图

使用Python绘制时间序列散点图
本文介绍如何使用Python的matplotlib库将时间序列数据转换为散点图,通过解析CSV文件中的日期时间并将其作为横坐标,实现数据的可视化展示。

今天需要以时间序列为横坐标绘制散点图,十分困难,因为scatter()都要求x为数字,在网上搜索时,搜到了一篇博文,尝试了一下真的成功,感谢感谢,在此转载,让更多人看到,感谢博主的分享:http://blog.51cto.com/happy366/2095768 (原文链接)

 # -*- coding: utf-8 -*-
        """
        speed1219.csv data file format:
        dtime,speed
        2017-12-19 10:33:30,803
        2017-12-19 10:35:29,1008
        2017-12-19 10:36:04,1016
        2017-12-19 10:37:32,984
        2017-12-19 10:38:06,1008
        """
        import pandas as pd
        import matplotlib.pyplot as plt
        from matplotlib.dates import AutoDateLocator, DateFormatter  

        df = pd.read_csv('d:/speed1219.csv',  parse_dates=['dtime'])
        plt.plot_date(df.dtime, df.speed, fmt='b.')

        ax = plt.gca()
        ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d %H:%M'))  #设置时间显示格式
        ax.xaxis.set_major_locator(AutoDateLocator(maxticks=24))       #设置时间间隔  

        plt.xticks(rotation=90, ha='center')
        label = ['speedpoint']
        plt.legend(label, loc='upper right')

        plt.grid()

        ax.set_title(u'传输速度', fontproperties='SimHei',fontsize=14)  
        ax.set_xlabel('dtime')
        ax.set_ylabel('Speed(KB/s)')

        plt.show()

其实这个是将线图改成·,关键就是这一句plt.plot_date(df.dtime, df.speed, fmt=‘b.’),其中的b.也能是b-,应该就是虚线啦。
但是这样也有一个问题,怎样修改散点图中的散点的大小呢?若有大佬知道的话,还请指导

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值