成功解决TypeError: distplot() got an unexpected keyword argument ‘y‘

简介: 成功解决TypeError: distplot() got an unexpected keyword argument ‘y‘

目录

解决问题

解决思路

解决方法


 

 

 

解决问题

TypeError: distplot() got an unexpected keyword argument 'y'

 

 

 

解决思路

类型错误:distplot()得到了一个意外的关键字参数'y'

 

 

 

解决方法

1. fg=sns.JointGrid(x=cols[0],y=cols[1],data=data_frame,)
2. fg.plot_marginals(sns.distplot)

distplot()函数中,只接受一个输入数据,即有x,没有y

1. def distplot Found at: seaborn.distributions
2. 
3. def distplot(a=None, bins=None, hist=True, kde=True, rug=False, fit=None, 
4.     hist_kws=None, kde_kws=None, rug_kws=None, fit_kws=None, 
5.     color=None, vertical=False, norm_hist=False, axlabel=None, 
6.     label=None, ax=None, x=None):
7. """DEPRECATED: Flexibly plot a univariate distribution of observations.
8.     
9.     .. warning::
10.     This function is deprecated and will be removed in a future version.
11.     Please adapt your code to use one of two new functions:
12.     
13.     - :func:`displot`, a figure-level function with a similar flexibility
14.     over the kind of plot to draw
15.     - :func:`histplot`, an axes-level function for plotting histograms,
16.     including with kernel density smoothing
17.     
18.     This function combines the matplotlib ``hist`` function (with automatic
19.     calculation of a good default bin size) with the seaborn :func:`kdeplot`
20.     and :func:`rugplot` functions. It can also fit ``scipy.stats``
21.     distributions and plot the estimated PDF over the data.
22.     
23.     Parameters
24.     ----------
25.     a : Series, 1d-array, or list.
26.     Observed data. If this is a Series object with a ``name`` attribute,
27.     the name will be used to label the data axis.
28.     bins : argument for matplotlib hist(), or None, optional
29.     Specification of hist bins. If unspecified, as reference rule is used
30.     that tries to find a useful default.
31.     hist : bool, optional
32.     Whether to plot a (normed) histogram.
33.     kde : bool, optional
34.     Whether to plot a gaussian kernel density estimate.
35.     rug : bool, optional
36.     Whether to draw a rugplot on the support axis.
37.     fit : random variable object, optional
38.     An object with `fit` method, returning a tuple that can be passed to a
39.     `pdf` method a positional arguments following a grid of values to
40.     evaluate the pdf on.
41.     hist_kws : dict, optional
42.     Keyword arguments for :meth:`matplotlib.axes.Axes.hist`.
43.     kde_kws : dict, optional
44.     Keyword arguments for :func:`kdeplot`.
45.     rug_kws : dict, optional
46.     Keyword arguments for :func:`rugplot`.
47.     color : matplotlib color, optional
48.     Color to plot everything but the fitted curve in.
49.     vertical : bool, optional
50.     If True, observed values are on y-axis.
51.     norm_hist : bool, optional
52.     If True, the histogram height shows a density rather than a count.
53.     This is implied if a KDE or fitted density is plotted.
54.     axlabel : string, False, or None, optional
55.     Name for the support axis label. If None, will try to get it
56.     from a.name if False, do not set a label.
57.     label : string, optional
58.     Legend label for the relevant component of the plot.
59.     ax : matplotlib axis, optional
60.     If provided, plot on this axis.
61.     
62.     Returns
63.     -------
64.     ax : matplotlib Axes
65.     Returns the Axes object with the plot for further tweaking.
66.     
67.     See Also
68.     --------
69.     kdeplot : Show a univariate or bivariate distribution with a kernel
70.     density estimate.
71.     rugplot : Draw small vertical lines to show each observation in a
72.     distribution.
73.     
74.     Examples
75.     --------
76.     
77.     Show a default plot with a kernel density estimate and histogram with bin
78.     size determined automatically with a reference rule:
79.     
80.     .. plot::
81.     :context: close-figs
82.     
83.     >>> import seaborn as sns, numpy as np
84.     >>> sns.set_theme(); np.random.seed(0)
85.     >>> x = np.random.randn(100)
86.     >>> ax = sns.distplot(x)
87.     
88.     Use Pandas objects to get an informative axis label:
89.     
90.     .. plot::
91.     :context: close-figs
92.     
93.     >>> import pandas as pd
94.     >>> x = pd.Series(x, name="x variable")
95.     >>> ax = sns.distplot(x)
96.     
97.     Plot the distribution with a kernel density estimate and rug plot:
98.     
99.     .. plot::
100.     :context: close-figs
101.     
102.     >>> ax = sns.distplot(x, rug=True, hist=False)
103.     
104.     Plot the distribution with a histogram and maximum likelihood gaussian
105.     distribution fit:
106.     
107.     .. plot::
108.     :context: close-figs
109.     
110.     >>> from scipy.stats import norm
111.     >>> ax = sns.distplot(x, fit=norm, kde=False)
112.     
113.     Plot the distribution on the vertical axis:
114.     
115.     .. plot::
116.     :context: close-figs
117.     
118.     >>> ax = sns.distplot(x, vertical=True)
119.     
120.     Change the color of all the plot elements:
121.     
122.     .. plot::
123.     :context: close-figs
124.     
125.     >>> sns.set_color_codes()
126.     >>> ax = sns.distplot(x, color="y")
127.     
128.     Pass specific parameters to the underlying plot functions:
129.     
130.     .. plot::
131.     :context: close-figs
132.     
133.     >>> ax = sns.distplot(x, rug=True, rug_kws={"color": "g"},
134.     ...                   kde_kws={"color": "k", "lw": 3, "label": "KDE"},
135.     ...                   hist_kws={"histtype": "step", "linewidth": 3,
136.     ...                             "alpha": 1, "color": "g"})
137.     
138.     """
139. if kde and not hist:
140.         axes_level_suggestion = "`kdeplot` (an axes-level function for kernel 
141.          density plots)."
142. else:
143.         axes_level_suggestion = "`histplot` (an axes-level function for 
144.          histograms)."
145.     msg = "`distplot` is a deprecated function and will be removed in a future 
146.      version. "\
147. "Please adapt your code to use either `displot` (a figure-level function 
148.      with "\
149. "similar flexibility) or " + axes_level_suggestion
150.     warnings.warn(msg, FutureWarning)
151. if ax is None:
152.         ax = plt.gca()
153. # Intelligently label the support axis
154.     label_ax = bool(axlabel)
155. if axlabel is None and hasattr(a, "name"):
156.         axlabel = a.name
157. if axlabel is not None:
158.             label_ax = True
159. # Support new-style API
160. if x is not None:
161.         a = x
162. # Make a a 1-d float array
163.     a = np.asarray(a, float)
164. if a.ndim > 1:
165.         a = a.squeeze()
166. # Drop null values from array
167.     a = remove_na(a)
168. # Decide if the hist is normed
169.     norm_hist = norm_hist or kde or fit is not None
170. # Handle dictionary defaults
171.     hist_kws = {} if hist_kws is None else hist_kws.copy()
172.     kde_kws = {} if kde_kws is None else kde_kws.copy()
173.     rug_kws = {} if rug_kws is None else rug_kws.copy()
174.     fit_kws = {} if fit_kws is None else fit_kws.copy()
175. # Get the color from the current color cycle
176. if color is None:
177. if vertical:
178.             line, = ax.plot(0, a.mean())
179. else:
180.             line, = ax.plot(a.mean(), 0)
181.         color = line.get_color()
182.         line.remove()
183. # Plug the label into the right kwarg dictionary
184. if label is not None:
185. if hist:
186.             hist_kws["label"] = label
187. elif kde:
188.             kde_kws["label"] = label
189. elif rug:
190.             rug_kws["label"] = label
191. elif fit:
192.             fit_kws["label"] = label
193. if hist:
194. if bins is None:
195.             bins = min(_freedman_diaconis_bins(a), 50)
196.         hist_kws.setdefault("alpha", 0.4)
197.         hist_kws.setdefault("density", norm_hist)
198.         orientation = "horizontal" if vertical else "vertical"
199.         hist_color = hist_kws.pop("color", color)
200.         ax.hist(a, bins, orientation=orientation, color=hist_color, **hist_kws)
201. if hist_color != color:
202.             hist_kws["color"] = hist_color
203. if kde:
204.         kde_color = kde_kws.pop("color", color)
205.         kdeplot(a, vertical=vertical, ax=ax, color=kde_color, **kde_kws)
206. if kde_color != color:
207.             kde_kws["color"] = kde_color
208. if rug:
209.         rug_color = rug_kws.pop("color", color)
210.         axis = "y" if vertical else "x"
211.         rugplot(a, axis=axis, ax=ax, color=rug_color, **rug_kws)
212. if rug_color != color:
213.             rug_kws["color"] = rug_color
214. if fit is not None:
215. def pdf(x):
216. return fit.pdf(x, *params)
217. 
218.         fit_color = fit_kws.pop("color", "#282828")
219.         gridsize = fit_kws.pop("gridsize", 200)
220.         cut = fit_kws.pop("cut", 3)
221.         clip = fit_kws.pop("clip", (-np.inf, np.inf))
222.         bw = stats.gaussian_kde(a).scotts_factor() * a.std(ddof=1)
223.         x = _kde_support(a, bw, gridsize, cut, clip)
224.         params = fit.fit(a)
225.         y = pdf(x)
226. if vertical:
227.             x, y = y, x
228.         ax.plot(x, y, color=fit_color, **fit_kws)
229. if fit_color != "#282828":
230.             fit_kws["color"] = fit_color
231. if label_ax:
232. if vertical:
233.             ax.set_ylabel(axlabel)
234. else:
235.             ax.set_xlabel(axlabel)
236. return ax

 

 

相关文章
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
|
1月前
|
Python
完美解决丨TypeError: fun() takes 2 positional arguments but 3 were given
完美解决丨TypeError: fun() takes 2 positional arguments but 3 were given
TypeError: custom() got an unexpected keyword argument ‘path‘
TypeError: custom() got an unexpected keyword argument ‘path‘
116 0
|
Dart 前端开发 JavaScript
Syntax Error: TypeError: this.getOptions is not a function
Syntax Error: TypeError: this.getOptions is not a function
473 0
Syntax Error: TypeError: this.getOptions is not a function
解决TypeError: __init__() takes from 1 to 3 positional arguments but 6 were given
解决TypeError: __init__() takes from 1 to 3 positional arguments but 6 were given
383 0
解决TypeError: __init__() takes from 1 to 3 positional arguments but 6 were given
python TypeError: missing 1 required positional argument:'self'
python TypeError: missing 1 required positional argument:'self'
python TypeError: missing 1 required positional argument:'self'
|
计算机视觉
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
TypeError: 'encoding' is an invalid keyword argument for this function
TypeError: 'encoding' is an invalid keyword argument for this function
234 0
|
Python
SyntaxError: Missing parentheses in call to 'print'
SyntaxError: Missing parentheses in call to 'print'
114 0