Reputation: 91
I'm using python 3 seaborn to generate the following subplots.
import numpy as np; np.random.seed(1)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(500, 12)
plt.subplot(2, 1, 1)
ax = sns.heatmap(uniform_data)
plt.subplot(2, 1, 2)
ax = sns.heatmap(uniform_data)
Both subplots use the same data but yet give different plots. I don't understand why.
Upvotes: 1
Views: 90
Reputation: 40667
I think the problem comes from the fact that you are trying to plot too many lines. If you reduce the size of your array, you can clearly see that the graphs are identical
import numpy as np; np.random.seed(1)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
plt.subplot(2, 1, 1)
ax = sns.heatmap(uniform_data)
plt.subplot(2, 1, 2)
ax = sns.heatmap(uniform_data)
but when you are trying to draw 500 lines in the small space of the figure, matplotlib cannot draw all the lines, and chooses a random(?) subset to display.
If you were to increase the size of the figure so that all the lines could be drawn, then you would again get the same output.
import numpy as np; np.random.seed(1)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(500, 12)
plt.figure(figsize=(10,30))
plt.subplot(2, 1, 1)
ax = sns.heatmap(uniform_data)
plt.subplot(2, 1, 2)
ax = sns.heatmap(uniform_data)
Upvotes: 1
Reputation: 2251
import numpy as np; np.random.seed(1)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(500, 12)
fig, axes = plt.subplots()
axes = sns.heatmap(uniform_data)
fig, axes = plt.subplots()
axes = sns.heatmap(uniform_data)
output:
Upvotes: 0