How To Share Axes After Adding Subplots Via Add_subplot?
I have a dataframe like this: df = pd.DataFrame({'A': [0.3, 0.2, 0.5, 0.2], 'B': [0.1, 0.0, 0.3, 0.1], 'C': [0.2, 0.5, 0.0, 0.7], 'D': [0.6, 0.3, 0.4, 0.6]}, index=list('abcd'))
Solution 1:
The question how to produce shared subplots in matplotlib:
- The SO seach engine results
- The matplotlib recipes or the examples page
What may be more interesting here, is that you could also directly use pandas to create the plot in a single line:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'A': [0.3, 0.2, 0.5, 0.2], 'B': [0.1, 0.0, 0.3, 0.1], 'C': [0.2, 0.5, 0.0, 0.7], 'D': [0.6, 0.3, 0.4, 0.6]}, index=list('abcd'))
df.plot(kind="bar", subplots=True, layout=(2,2), sharey=True, sharex=True)
plt.show()
Post a Comment for "How To Share Axes After Adding Subplots Via Add_subplot?"