How to draw multiple graphs in one area. For example, this article imports matplotlib in addition to pandas and draws. However, this time I will write about how to draw using only the pandas library.
As shown below, it seems that it can be realized by substituting the drawing information of the first graph into ax1 and substituting ax1 which is the first graph information into ax of the plot argument of the second graph. By doing this, it can be written concisely without using matplotlib.
import pandas as pd
import numpy as np
#Creating a data frame.
df = pd.DataFrame(np.arange(12).reshape(4, 3),
columns=["colA", "colB", "colC"],
index=["row1", "row2", "row3", "row4"])
#First graph.
ax1 = df.plot(x="colA", y="colB")
#Second graph.
df.plot(x="colA", y="colC", ax = ax1)
And the output result is as follows.
https://stackoverflow.com/questions/42128467/matplotlib-plot-multiple-columns-of-pandas-data-frame-on-the-bar-chart/42131286
Recommended Posts