SoFunction
Updated on 2024-12-14

python method for drawing graphs with time series variations

There are two things to consider when drawing this kind of diagram:

1. How to generate a continuous timeline

2. How to display the style and number of axis labels appropriately in the diagram.

import  as plt
import matplotlib as mpl
import numpy as np
% matplotlib inline
import datetime# This bag is key
#Set start and end times
start=(2013,1,1)
stop=(2013,12,31)
delta=(1)# Set date interval
dates=(start,stop,delta)# Returns a date sequence of floating point type, this generates a time sequence, similarly what if the sequence is converted to a date?
values=(len(dates))
# There are two problems, one is that the axes are not labeled in the form of dates, and the other is that the number and placement of the scales are not appropriate
fig=(figsize=(24,12))# Resize the drawing space
(dates,values,linestyle='-',marker='*',c='r',alpha=0.5)#Mapping
ax=()
date_format=('%Y-%m-%d')# Set the format of the display
.set_major_formatter(date_format)# Setting the x-axis main format
.set_major_locator((30))#Set the scale interval for the display of the axes.
fig.autofmt_xdate()#take precautionsxOverlapping data on the axes,automatic adjustment。

To this point this article on python basic drawing on the time series of changes in the drawing of the graph is introduced to this article, more related python basic drawing content please search my previous articles or continue to browse the following related articles I hope you will support me in the future more!