我想画一些应该是这样的东西:
对于一个可复制的例子,让我提供一些玩具数据:toy_data
Principal Gender loan_status
0 1 0 PAIDOFF
1 1 1 PAIDOFF
2 1 0 PAIDOFF
3 1 1 PAIDOFF
4 1 0 PAIDOFF
341 0.714286 0 COLLECTION
342 1 0 COLLECTION
343 0.714286 0 COLLECTION
344 1 0 COLLECTION
345 1 0 COLLECTION
或者选择:
^{pr2}$
我的代码如下:bins=np.linspace(toy_data.Principal.min(), toy_data.Principal.max(), 10)
g = sns.FacetGrid(toy_data, col="Gender", hue="loan_status", palette="Set1", col_wrap=2)
g.map(plt.hist, 'Principal', bins=bins, ec="k")
g.axes[-1].legend()
plt.show()
返回以下错误消息:---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
1 bins=np.linspace(toy_data.Principal.min(), toy_data.Principal.max(), 10)
2 g = sns.FacetGrid(toy_data, col="Gender", hue="loan_status", palette="Set1", col_wrap=2)
----> 3 g.map(plt.hist, 'Principal', bins=bins, ec="k")
4
5 g.axes[-1].legend()
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\axisgrid.py in map(self, func, *args, **kwargs)
741
742 # Draw the plot
--> 743 self._facet_plot(func, ax, plot_args, kwargs)
744
745 # Finalize the annotations and layout
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
825
826 # Draw the plot
--> 827 func(*plot_args, **plot_kwargs)
828
829 # Sort out the supporting information
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs)
3130 histtype=histtype, align=align, orientation=orientation,
3131 rwidth=rwidth, log=log, color=color, label=label,
-> 3132 stacked=stacked, normed=normed, data=data, **kwargs)
3133 finally:
3134 ax._hold = washold
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1853 "the Matplotlib list!)" % (label_namer, func.__name__),
1854 RuntimeWarning, stacklevel=2)
-> 1855 return func(ax, *args, **kwargs)
1856
1857 inner.__doc__ = _add_data_doc(inner.__doc__,
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(***failed resolving arguments***)
6502 color = mcolors.to_rgba_array(color)
6503 if len(color) != nx:
-> 6504 raise ValueError("color kwarg must have one color per dataset")
6505
6506 # If bins are not specified either explicitly or via range,
ValueError: color kwarg must have one color per dataset
我不知道我为什么会收到这个错误消息,以及我应该怎么做来更正它。在