Why is the first subplot skipped? [duplicate] - seaborn

This question already has an answer here:
seaborn is not plotting within defined subplots
(1 answer)
Closed 7 months ago.
I was trying to create visualize a variable using sns.distplot() and sns.boxplot()
the code
I got this result:
result
Apparently,first subplot is skipped.Does anyone know why this is happening?

The reason you are seeing the displot outside is because it is a figure-level function and you cannot use ax in it. You can change it to histplot and should see it working...
fig, axes = plt.subplots(2,1,figsize=(5,5))
sns.histplot(wine['fixed acidity'], ax=axes[0])
sns.boxplot(wine['fixed acidity'], ax=axes[1])
Plot

Related

Edit labels and move legend in seaborn [duplicate]

This question already has answers here:
Edit legend title and labels of Seaborn scatterplot and countplot
(3 answers)
How to edit a seaborn legend title and labels for figure-level functions
(2 answers)
How to customize seaborn.scatterplot legends?
(1 answer)
Closed 7 months ago.
I have a seaborn scatterplot, which I want to change its labels and move the legend outside the graph. There are many solutions to fix each of the issues, but I cannot fix both of them simultaneously. Adapted from a solution in stackoverflow which was intended for sns.lmplot:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
g = sns.scatterplot(x="total_bill", y="tip", hue="smoker", data=tips, legend=False)
plt.legend(title='Smoker', bbox_to_anchor=(1.05, 1), labels=['Hell Yeh', 'Nah Bruh'])
plt.show(g)
Here legend=False and is defined later by matplotlib. The issue is the plot only displays the first label and not the rest in the legend.
I have tried another way to modify the label by legend='full' and later modifying it:
g = sns.scatterplot(x="total_bill", y="tip", hue="smoker", data=tips, legend='full')
h,l = g.get_legend_handles_labels()
l = ['Smoking behaviors:','Hell Yeh', 'Nah Bruh']
g.legend(h, l)
but the command g.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)does not work properly and edited labels do not show up. Only original labels are shown.
So, I can fix both of these issues separately, but not at the same time.
In the current version of Seaborn's scatterplot (0.11.1), you can first create the legend in full and afterwards change it by calling ax.legend() again.
Note that the return value of sns.scatterplot is an ax as it is an axes-level function. This should not be confused with figure level functions which return a complete grid of "axes" and often are written as g = sns....
Different seaborn functions create legends in different ways. Depending on the options used, the legend can become quite intricate and not easy to change. Making legends easier to modify is planned in Seaborn's future developments.
from matplotlib import pyplot as plt
import seaborn as sns
tips = sns.load_dataset('tips')
ax = sns.scatterplot(x="total_bill", y="tip", hue="smoker", data=tips, legend='full')
ax.legend(title='Smoker', bbox_to_anchor=(1.05, 1), labels=['Hell Yeh', 'Nah Bruh'])
plt.tight_layout()
plt.show()

d3 log scale always returning NaN [duplicate]

This question already has answers here:
X scale function in D3.js keeps returning undefined
(1 answer)
D3.js error using timescale (path is NaN)
(1 answer)
Closed 3 years ago.
I am trying to use log scale for y-axis of my line chart. The log scale just doesnt seem to work - it always returns NaN. Heres what I am trying:
Where am I going wrong?

How can I save an image in Python? [duplicate]

This question already has answers here:
How to capture pygame screen?
(4 answers)
Closed 5 years ago.
I've made a really basic drawing program in Python with Pygame. The program has a square window, in which you draw. How could I save the area inside the window as an image?
As downshift commented, use pygame.image.save
win = pygame.display.set_mode(...)
# your stuff
pygame.image.save(win, "screenshot.jpg")

Ipython notebook: show for-loop images "realtime", before next step [duplicate]

This question already has answers here:
How to dynamically update a plot in a loop in IPython notebook (within one cell)
(7 answers)
Closed 7 years ago.
Running following code in an ipython/jupyter notebook:
for i in range(4):
# any figure
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(range(i), range(i))
fig.show()
# do something that takes a long time:
a = fib(500000)
results in all the figures being visible at the same time (after the 4th loop).
How can I change my setup so that the figures become visible as soon as they have been calculated (before the next step in the for loop)?
N.B. I'm using %matplotlib inline
First, import display:
from IPython import display
and replace fig.show() by display.display(fig)

export from Three.js to .obj [duplicate]

This question already has an answer here:
Exporting Threejs Scene to Obj Format
(1 answer)
Closed 5 years ago.
I've seen a lot of explanations for how to import .obj files into Three.js, but I was wondering if there was a way to do the opposite? I have a Three.js program that can randomly generate shapes, and I want to export them as .obj files. Is there a way to do this?
Or, if not, is there another programming format that I should recreate my code with that does have this ability? Thank you.
You should be able to use the OBJExporter.

Resources