Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

line plot python only years datetime index

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

dates = pd.date_range('20070101',periods=1000)
df = pd.DataFrame(np.random.randn(1000), index = dates, columns =list ('A'))

fig,ax = plt.subplots()
df.plot(x_compat=True,ax=ax)

ax.xaxis.set_tick_params(reset=True)
ax.xaxis.set_major_locator(mdates.YearLocator(1))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y'))

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: rolling window pandas 
Python :: python code execution time 
Python :: install os conda 
Python :: break while loop python 
Python :: set python 3 as default mac 
Python :: python urlparse get domain 
Python :: python list files in folder with wildcard 
Python :: python to make video 
Python :: connect mongodb with python 
Python :: sort and reverse list in python 
Python :: python get first letter of string 
Python :: remove decimal python 
Python :: Publish Image msg ros python 
Python :: 2d array in python 
Python :: matplotlib larger chart 
Python :: image resize in python 
Python :: Python message popup 
Python :: wav file to array python 
Python :: python input string 
Python :: sqlalchemy convert row to dict 
Python :: best fit line python log log scale 
Python :: python replace n with actual new line 
Python :: python gzip a file 
Python :: pandas dataframe add two columns int and string 
Python :: Python NumPy ndarray flatten Function Example 
Python :: url_for 
Python :: uses specific version python venv 
Python :: restrict ticks to integers matplotlib 
Python :: random letters generator python 
Python :: too many python versions pip package location 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =