import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import itertools
# create test dataframe
df = pd.DataFrame({
'FID_Json_M': [1903, 1904, 1905],
'maxspeed': [50,50,50],
'direction': ['South','South','South'],
'roadtype': ['secondary','secondary','secondary']
})
# define colors for subplots
colors = ['red', 'green', 'blue', 'orange']
# create 2 x 2 subplots
fig, axes = plt.subplots(nrows = 2, ncols = 2)
# set padding between subplots
fig.tight_layout(pad=1.0)
# iterate over subplots in figure and colunds in dataframe
for col, ax in zip(df.columns, list(itertools.chain(*axes))):
# create histogram for each data series using specified color
ax.hist(df[col], color = colors[list(df.columns).index(col)])
plt.show()
下面是一个具有一些自定义功能的示例:
相关问题 更多 >
编程相关推荐