Seaborn lmplot hue plotting error
$begingroup$
I am trying to colour the points on an lmplot by a categorical variable contained within a column of a DataFrame and I am getting the following error:
ValueError Traceback (most recent call last)
<ipython-input-58-e0ac8c5bf9eb> in <module>
----> 1 sns.lmplot(x='TDS', y='Li', data=df_sub, hue='Group Location', legend=True)
2 plt.show()
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lmplot(x, y, data, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, size)
587 scatter_kws=scatter_kws, line_kws=line_kws,
588 )
--> 589 facets.map_dataframe(regplot, x, y, **regplot_kws)
590
591 # Add a legend
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in map_dataframe(self, func, *args, **kwargs)
818
819 # Draw the plot
--> 820 self._facet_plot(func, ax, args, kwargs)
821
822 # Finalize the annotations and layout
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
836
837 # Draw the plot
--> 838 func(*plot_args, **plot_kwargs)
839
840 # Sort out the supporting information
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
787 scatter_kws["marker"] = marker
788 line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 789 plotter.plot(ax, scatter_kws, line_kws)
790 return ax
791
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in plot(self, ax, scatter_kws, line_kws)
342 self.scatterplot(ax, scatter_kws)
343 if self.fit_reg:
--> 344 self.lineplot(ax, line_kws)
345
346 # Label the axes
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lineplot(self, ax, kws)
387
388 # Fit the regression model
--> 389 grid, yhat, err_bands = self.fit_regression(ax)
390
391 # Get set default aesthetics
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_regression(self, ax, x_range, grid)
206 yhat, yhat_boots = self.fit_logx(grid)
207 else:
--> 208 yhat, yhat_boots = self.fit_fast(grid)
209
210 # Compute the confidence interval at each grid point
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_fast(self, grid)
228
229 beta_boots = algo.bootstrap(X, y, func=reg_func,
--> 230 n_boot=self.n_boot, units=self.units).T
231 yhat_boots = grid.dot(beta_boots).T
232 return yhat, yhat_boots
C:ProgramDataAnaconda3libsite-packagesseabornalgorithms.py in bootstrap(*args, **kwargs)
84 boot_dist =
85 for i in range(int(n_boot)):
---> 86 resampler = rs.randint(0, n, n)
87 sample = [a.take(resampler, axis=0) for a in args]
88 boot_dist.append(f(*sample, **func_kwargs))
mtrand.pyx in mtrand.RandomState.randint()
ValueError: low >= high
The categororical variable is a string.
seaborn
$endgroup$
|
show 1 more comment
$begingroup$
I am trying to colour the points on an lmplot by a categorical variable contained within a column of a DataFrame and I am getting the following error:
ValueError Traceback (most recent call last)
<ipython-input-58-e0ac8c5bf9eb> in <module>
----> 1 sns.lmplot(x='TDS', y='Li', data=df_sub, hue='Group Location', legend=True)
2 plt.show()
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lmplot(x, y, data, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, size)
587 scatter_kws=scatter_kws, line_kws=line_kws,
588 )
--> 589 facets.map_dataframe(regplot, x, y, **regplot_kws)
590
591 # Add a legend
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in map_dataframe(self, func, *args, **kwargs)
818
819 # Draw the plot
--> 820 self._facet_plot(func, ax, args, kwargs)
821
822 # Finalize the annotations and layout
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
836
837 # Draw the plot
--> 838 func(*plot_args, **plot_kwargs)
839
840 # Sort out the supporting information
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
787 scatter_kws["marker"] = marker
788 line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 789 plotter.plot(ax, scatter_kws, line_kws)
790 return ax
791
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in plot(self, ax, scatter_kws, line_kws)
342 self.scatterplot(ax, scatter_kws)
343 if self.fit_reg:
--> 344 self.lineplot(ax, line_kws)
345
346 # Label the axes
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lineplot(self, ax, kws)
387
388 # Fit the regression model
--> 389 grid, yhat, err_bands = self.fit_regression(ax)
390
391 # Get set default aesthetics
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_regression(self, ax, x_range, grid)
206 yhat, yhat_boots = self.fit_logx(grid)
207 else:
--> 208 yhat, yhat_boots = self.fit_fast(grid)
209
210 # Compute the confidence interval at each grid point
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_fast(self, grid)
228
229 beta_boots = algo.bootstrap(X, y, func=reg_func,
--> 230 n_boot=self.n_boot, units=self.units).T
231 yhat_boots = grid.dot(beta_boots).T
232 return yhat, yhat_boots
C:ProgramDataAnaconda3libsite-packagesseabornalgorithms.py in bootstrap(*args, **kwargs)
84 boot_dist =
85 for i in range(int(n_boot)):
---> 86 resampler = rs.randint(0, n, n)
87 sample = [a.take(resampler, axis=0) for a in args]
88 boot_dist.append(f(*sample, **func_kwargs))
mtrand.pyx in mtrand.RandomState.randint()
ValueError: low >= high
The categororical variable is a string.
seaborn
$endgroup$
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago
|
show 1 more comment
$begingroup$
I am trying to colour the points on an lmplot by a categorical variable contained within a column of a DataFrame and I am getting the following error:
ValueError Traceback (most recent call last)
<ipython-input-58-e0ac8c5bf9eb> in <module>
----> 1 sns.lmplot(x='TDS', y='Li', data=df_sub, hue='Group Location', legend=True)
2 plt.show()
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lmplot(x, y, data, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, size)
587 scatter_kws=scatter_kws, line_kws=line_kws,
588 )
--> 589 facets.map_dataframe(regplot, x, y, **regplot_kws)
590
591 # Add a legend
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in map_dataframe(self, func, *args, **kwargs)
818
819 # Draw the plot
--> 820 self._facet_plot(func, ax, args, kwargs)
821
822 # Finalize the annotations and layout
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
836
837 # Draw the plot
--> 838 func(*plot_args, **plot_kwargs)
839
840 # Sort out the supporting information
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
787 scatter_kws["marker"] = marker
788 line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 789 plotter.plot(ax, scatter_kws, line_kws)
790 return ax
791
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in plot(self, ax, scatter_kws, line_kws)
342 self.scatterplot(ax, scatter_kws)
343 if self.fit_reg:
--> 344 self.lineplot(ax, line_kws)
345
346 # Label the axes
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lineplot(self, ax, kws)
387
388 # Fit the regression model
--> 389 grid, yhat, err_bands = self.fit_regression(ax)
390
391 # Get set default aesthetics
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_regression(self, ax, x_range, grid)
206 yhat, yhat_boots = self.fit_logx(grid)
207 else:
--> 208 yhat, yhat_boots = self.fit_fast(grid)
209
210 # Compute the confidence interval at each grid point
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_fast(self, grid)
228
229 beta_boots = algo.bootstrap(X, y, func=reg_func,
--> 230 n_boot=self.n_boot, units=self.units).T
231 yhat_boots = grid.dot(beta_boots).T
232 return yhat, yhat_boots
C:ProgramDataAnaconda3libsite-packagesseabornalgorithms.py in bootstrap(*args, **kwargs)
84 boot_dist =
85 for i in range(int(n_boot)):
---> 86 resampler = rs.randint(0, n, n)
87 sample = [a.take(resampler, axis=0) for a in args]
88 boot_dist.append(f(*sample, **func_kwargs))
mtrand.pyx in mtrand.RandomState.randint()
ValueError: low >= high
The categororical variable is a string.
seaborn
$endgroup$
I am trying to colour the points on an lmplot by a categorical variable contained within a column of a DataFrame and I am getting the following error:
ValueError Traceback (most recent call last)
<ipython-input-58-e0ac8c5bf9eb> in <module>
----> 1 sns.lmplot(x='TDS', y='Li', data=df_sub, hue='Group Location', legend=True)
2 plt.show()
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lmplot(x, y, data, hue, col, row, palette, col_wrap, height, aspect, markers, sharex, sharey, hue_order, col_order, row_order, legend, legend_out, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, x_jitter, y_jitter, scatter_kws, line_kws, size)
587 scatter_kws=scatter_kws, line_kws=line_kws,
588 )
--> 589 facets.map_dataframe(regplot, x, y, **regplot_kws)
590
591 # Add a legend
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in map_dataframe(self, func, *args, **kwargs)
818
819 # Draw the plot
--> 820 self._facet_plot(func, ax, args, kwargs)
821
822 # Finalize the annotations and layout
C:ProgramDataAnaconda3libsite-packagesseabornaxisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
836
837 # Draw the plot
--> 838 func(*plot_args, **plot_kwargs)
839
840 # Sort out the supporting information
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in regplot(x, y, data, x_estimator, x_bins, x_ci, scatter, fit_reg, ci, n_boot, units, order, logistic, lowess, robust, logx, x_partial, y_partial, truncate, dropna, x_jitter, y_jitter, label, color, marker, scatter_kws, line_kws, ax)
787 scatter_kws["marker"] = marker
788 line_kws = {} if line_kws is None else copy.copy(line_kws)
--> 789 plotter.plot(ax, scatter_kws, line_kws)
790 return ax
791
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in plot(self, ax, scatter_kws, line_kws)
342 self.scatterplot(ax, scatter_kws)
343 if self.fit_reg:
--> 344 self.lineplot(ax, line_kws)
345
346 # Label the axes
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in lineplot(self, ax, kws)
387
388 # Fit the regression model
--> 389 grid, yhat, err_bands = self.fit_regression(ax)
390
391 # Get set default aesthetics
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_regression(self, ax, x_range, grid)
206 yhat, yhat_boots = self.fit_logx(grid)
207 else:
--> 208 yhat, yhat_boots = self.fit_fast(grid)
209
210 # Compute the confidence interval at each grid point
C:ProgramDataAnaconda3libsite-packagesseabornregression.py in fit_fast(self, grid)
228
229 beta_boots = algo.bootstrap(X, y, func=reg_func,
--> 230 n_boot=self.n_boot, units=self.units).T
231 yhat_boots = grid.dot(beta_boots).T
232 return yhat, yhat_boots
C:ProgramDataAnaconda3libsite-packagesseabornalgorithms.py in bootstrap(*args, **kwargs)
84 boot_dist =
85 for i in range(int(n_boot)):
---> 86 resampler = rs.randint(0, n, n)
87 sample = [a.take(resampler, axis=0) for a in args]
88 boot_dist.append(f(*sample, **func_kwargs))
mtrand.pyx in mtrand.RandomState.randint()
ValueError: low >= high
The categororical variable is a string.
seaborn
seaborn
edited yesterday
P Griffin
asked yesterday
P GriffinP Griffin
63
63
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago
|
show 1 more comment
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:
sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:
sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45879%2fseaborn-lmplot-hue-plotting-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f45879%2fseaborn-lmplot-hue-plotting-error%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Could you share the code that caused the error, please? If not, would you alternatively be able to extract a simplified example that illustrates the problem?
$endgroup$
– mapto
yesterday
$begingroup$
Sure. It was a simple one liner, something like this:
sns.lmplot(x='col1', y='col2', data=df, hue='col3')
$endgroup$
– P Griffin
yesterday
$begingroup$
If you remove the hue parameter, does it work?
$endgroup$
– Tasos
20 hours ago
$begingroup$
Yes, it works fine without the hue parameter.
$endgroup$
– P Griffin
18 hours ago
$begingroup$
Could it be because there are only one of some of the categorical variables?
$endgroup$
– P Griffin
17 hours ago