Python Draw time Series scatter plot

Source: Internet
Author: User
Tags pandas plot

In operation and maintenance management, often encounter time series data, such as network card traffic, number of online users, number of concurrent connections, and so on. Scatter plots are used to visually visualize the distribution of data.

The Pyplot of the Matplotlib module has a function of drawing a scatter plot, but the function requires that the x-axis be a numeric type. In the Pandas plot function, the scatter chart type ' Scatter ' also requires a digital type, with the time type of error. After reading dozens of articles in the search, the paper explores the simple way to draw a scatter plot. Scatter plots can be drawn using Pyplot's Plot_date ().

Here's the full Python code:

        #-*-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 I Mport 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.se        T_title (U ' transfer rate ', fontproperties= ' Simhei ', fontsize=14) Ax.set_xlabel (' Dtime ') Ax.set_ylabel (' Speed (kb/s) ') Plt.show ()

If not, you can delete the line starting with ax. Keep only the following lines of code:

        df = pd.read_csv(‘d:/speed1219.csv‘,  parse_dates=[‘dtime‘])        plt.plot_date(df.dtime, df.speed, fmt=‘b.‘)        plt.xticks(rotation=90, ha=‘center‘)        plt.grid()        plt.show()

Python Draw time Series scatter plot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.