[PYTHON] Tips for plotting multiple lines with pandas

Introduction

I check it every time.

If you pass an ax array when subplots = True, it will subplot nicely, and if you specify cmap to change the color for each line, there is not much information, so it may be useful for someone.

The one I use often

import matplotlib.pyplot as plt
from matplotlib import cm

_, ax = plt.subplots(2,1, figsize=(16, 8))
df.plot(
    grid=True, #Attach the grid
    style='-', #Specifying the line style
    cmap=cm.tab20, #Change line colormap
    subplots=True, #Separate subplot for each line
    ax=axes, #Number of columns and len(axes)If there is, it will subplot nicely
)
plt.show()

Color map

Postscript

--You can use cm.get_cmap ("tab20 ") instead of cm.tab20. --You can use cm.tab20.colors [n] for colors such as plt.plot.

Recommended Posts

Tips for plotting multiple lines with pandas
Data processing tips with Pandas
Pandas / DataFrame Tips for practical use
Tips for running Go with docker
Versatile data plotting with pandas + matplotlib
Comment out multiple lines with csh
Extract specific multiple columns with pandas
Tips for dealing with binaries in Python
Tips for using python + caffe with TSUBAME
Process multiple lists with for in Python
Best practices for messing with data with pandas
Pandas basics for beginners ③ Histogram creation with matplotlib
[pandas] GroupBy Tips
~ Tips for Python beginners from Pythonista with love ① ~
Update multiple tables at once with pandas to_sql
~ Tips for Python beginners from Pythonista with love ② ~
Python text reading for multiple lines and one line
Extract N samples for each group with Pandas DataFrame
[For beginners] Script within 10 lines (8. Plot map with folium [2]
(For those unfamiliar with Matplotlib) Tips for drawing graphs with Seaborn
Tips for speeding up python code correctly with numba
Tips for opening a scene with a broken reference with a script
Create an environment for test automation with AirtestIDE (Tips)
[For recording] Pandas memorandum
Multiple selections with Jupyter
Quickly visualize with Pandas
Processing datasets with pandas (1)
Bootstrap sampling with Pandas
Convert 202003 to 2020-03 with pandas
Processing datasets with pandas (2)
[Tips] My Pandas Note
Merge datasets with pandas
Learn Pandas with Cheminformatics
Data visualization with pandas
Data manipulation with Pandas!
Shuffle data with pandas