这里有一个通用的解决方案,即包含 17 个 matplotlib 图形实用程序 + 用户指南的免费库:https://www.mlbridgeresearch.com/products/free-article-2。我厌倦了为了编写实用软件而中断研究,因此我积累了满足常见需求的库。该代码有据可查,并且运行良好。这是一个例子。
from sklearn.datasets import load_iris
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from statistics_utilities import histogram
from statistics_utilities import box_plot_basic
data = load_iris()
# iris, using the label column as a categorical
df = pd.DataFrame(data.data, columns=data.feature_names)
df['label'] = data.target
print(data.feature_names)
# setup the plot grid
plt.style.use('seaborn-darkgrid')
fig, ax = plt.subplots(1, 2)
ax = np.reshape(ax, (1, 2))
variable_name = 'sepal length (cm)'
# Place the histogram on the grid - pass the Axes.
# Plots a single histogram for a quantitative variable using seaborn's distplot().
# See also histogram_grid(), which plots a grid of histograms for a list of
# quantitative variables
hist_type = 'frequency'
# displays summary statistics in a custom legend, set legend=False to turn off.
ax[0, 0] = histogram(df, variable_name=variable_name, bins=20, kde=False, statistics='all',
hist_type=hist_type, title=None, ax=ax[0, 0])
# Place the box plot on the grid - pass the Axes
# Plots a single box_plot for a quantitative variable using matplotlib's boxplot().
# See also box_plot() and box_plot_groupby, which plots a quantitative variable
# by one or two categorical variables.
box_orientation = 'vertical'
box_width = .2
ax[0, 1] = box_plot_basic(df, variable_name=variable_name,
box_orientation=box_orientation, box_width=box_width, title=None,
ax=ax[0, 1])
# adjustments to plot size and spacing
fig.set_size_inches(13, 6)
fig.subplots_adjust(wspace=.55, left=0.035, right=.985, top=.925, bottom=.1)
fig.suptitle('iris dataset', fontsize=13)
plt.show()
plt.close()