About the X-axis notation of Matplotlib bar graphs

For bar charts

Store date strings in array b at "moderate intervals" and set with set_xticklabels

hoge.py


import numpy as np
import matplotlib.pyplot as plt

ax = df.plot(kind='bar', color=['b','r','g'] , label ='hoge' ,alpha=0.3 )  
#ax = plt.gca()

ln = len(df.index)
a = np.arange(ln)+1
b = []
for i in a-1:
    b.append("") if i%5!=0 else b.append(str(df.index[i].strftime('%m/%d')))
#print(b)
ax.set_xticklabels(b,rotation =15)

For line graphs

X-axis notation is set by ax.xaxis.set_major_formatter etc.

hoge.py


ax = df.plot(kind='line', color=['b','r','g'] , label ='hoge' ,alpha=0.3 )  

years = mdates.MonthLocator(interval=3)
months = mdates.MonthLocator()
daysFmt = mdates.DateFormatter("%m/%d")

ax.xaxis.set_major_locator(years)
ax.xaxis.set_minor_locator(months)
ax.xaxis.set_major_formatter( daysFmt )

Recommended Posts

About the X-axis notation of Matplotlib bar graphs
About the size of matplotlib points
About the ease of Python
Change the style of matplotlib
About the components of Luigi
About the features of Python
About the return value of pthread_mutex_init ()
About the return value of the histogram.
About the basic type of Go
About the upper limit of threads-max
Unravel the mystery of matplotlib specgram
About the behavior of yield_per of SqlAlchemy
About the basics list of Python basics
Change the Y-axis scale of Matplotlib to exponential notation (10 Nth power notation)
This and that of the inclusion notation.
Align the size of the colorbar with matplotlib
About the behavior of enable_backprop of Chainer v2
About the virtual environment of python version 3.7
Memorandum of python beginners About inclusion notation
About the arguments of the setup function of PyCaret
About Japanese fonts of matplotlib (for Mac)
About the Normal Equation of Linear Regression
About the accuracy of Archimedean circle calculation method
About the behavior of copy, deepcopy and numpy.copy
About the processing speed of SVM (SVC) of scikit-learn
Increase the font size of the graph with matplotlib
One liner that lists the colors of matplotlib
A note about the python version of python virtualenv
About the development contents of machine learning (Example)
[Note] About the role of underscore "_" in Python
Put the second axis in 2dhistgram of matplotlib
About the behavior of Model.get_or_create () of peewee in Python
The basis of graph theory with matplotlib animation
Code for checking the operation of Python Matplotlib
Visualize the behavior of the sorting algorithm with matplotlib
Make progress of dd visible in the progress bar
About the behavior of Queue during parallel processing
About the * (asterisk) argument of python (and itertools.starmap)
(Matplotlib) Tips for adjusting the appearance of graphs [Axis / Picture frame / Scale / Scale character edition]
About the queue
[Jupyter] [Python] Correct the deviation between the x-axis scale and the center line of the bar with hist of matplotlib (for counting in 1 increments)
A memorandum about the warning of the pylint output result
Add information to the bottom of the figure with Matplotlib
Omit the decimal point of the graph scale in matplotlib
Think about the next generation of Rack and WSGI
About testing in the implementation of machine learning models
About the inefficiency of data transfer in luigi on-memory
About the uncluttered arrangement in the import order of flake8
A story about changing the master name of BlueZ
Personal notes about the integration of vscode and anaconda
A reminder about the implementation of recommendations in Python
[Introduction to Python] Basic usage of the library matplotlib
Adjust the ratio of multiple figures with the matplotlib gridspec