I'm new to python/matplotlib, while I'm experimenting I encourage this strange behavior that the produced chart always shows those points(dates) that ain't exist on my series. I tried to search from the doc and web but couldn't find much clue. Here's how I produced the chart:
import pymysql import datetime import pandas as pd import matplotlib.pyplot as plt serial_no = '163406' start_date = '2020-06-28' mysql = pymysql.connect(host="localhost",port=3306,user="dbuser",passwd="psword",db="expdb") cursor = mysql.cursor() sql = "select r.t_date ,r.acc_av from expdb.records r \ where r.sn = '"+serial_no+"'and r.t_date >= '"+start_date+"' order by r.t_date ASC" data= pd.read_sql(sql, mysql, parse_dates=['t_date']) data = data.set_index('t_date') plt.plot_date(fdata.index,data[['acc_av']],linestyle=':', marker='.', label='acc av') plt.show()
The datatype of datatype:
fund_df.info() <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 32 entries, 2020-11-30 to 2021-01-13 Data columns (total 1 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 acc_av 32 non-null float64 dtypes: float64(5) memory usage: 1.5 KB
A few sample data:
data.head(10) acc_av t_date 2020-11-30 7.0706 2020-12-01 7.2280 2020-12-02 7.2234 2020-12-03 7.2360 2020-12-04 7.2889 2020-12-07 7.2660 2020-12-08 7.2721 2020-12-09 7.1850 2020-12-10 7.1953 2020-12-11 7.1542
There are few days certainly not in the series, ie 2020-12-05, 2020-12-06.
From the chart it produced, even the markers of these nonexistent dates, the timeframe appears still exists on the chart, that showing longer interval space from 12-04 to 12-07, for instance, it's the same regardless I used plt.plot() or plt.plot_date(). Is there a way to avoid matplotlib automatically put in these nonexistent date back into the chart ?
https://stackoverflow.com/questions/65820966/matplotlib-plot-date-automatically-adds-in-dates-no-on-my-data-series-why-and-h January 21, 2021 at 11:56AM
没有评论:
发表评论