ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Oct 2012 17:33:01 -0500Colorbar for density plotshttps://ask.sagemath.org/question/9460/colorbar-for-density-plots/Hi!
I would like to know if there is a way to get a colorbar for a density plot. For contour plots this works fine with the colorbar=True option, but for density plots there doesn't seem to be such an option. Can anyone help?
Greetings,
MelvinTue, 23 Oct 2012 13:57:25 -0500https://ask.sagemath.org/question/9460/colorbar-for-density-plots/Answer by Shashank for <p>Hi!</p>
<p>I would like to know if there is a way to get a colorbar for a density plot. For contour plots this works fine with the colorbar=True option, but for density plots there doesn't seem to be such an option. Can anyone help?</p>
<p>Greetings,
Melvin</p>
https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?answer=14181#post-id-14181I don't know the answer in sage but it is easy in matplotlib
import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
array=np.zeros((100,100))
for i in range(100):
for j in range(100):
array[i][j]=sin(0.1*i)*cos(0.1*j)
#norm=matplotlib.colors.Normalize(0.995,1.0)
im1 = plt.imshow(array, cmap=cm.hot, origin='lower',clip_on=True,filternorm=1)
#im1.set_norm(norm)
plt.colorbar()
plt.savefig('test.png')Tue, 23 Oct 2012 16:20:24 -0500https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?answer=14181#post-id-14181Comment by kcrisman for <p>I don't know the answer in sage but it is easy in matplotlib</p>
<pre><code>import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
array=np.zeros((100,100))
for i in range(100):
for j in range(100):
array[i][j]=sin(0.1*i)*cos(0.1*j)
#norm=matplotlib.colors.Normalize(0.995,1.0)
im1 = plt.imshow(array, cmap=cm.hot, origin='lower',clip_on=True,filternorm=1)
#im1.set_norm(norm)
plt.colorbar()
plt.savefig('test.png')
</code></pre>
https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?comment=18822#post-id-18822Want to take a stab at #9150?Tue, 23 Oct 2012 16:27:55 -0500https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?comment=18822#post-id-18822Comment by Shashank for <p>I don't know the answer in sage but it is easy in matplotlib</p>
<pre><code>import matplotlib
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
array=np.zeros((100,100))
for i in range(100):
for j in range(100):
array[i][j]=sin(0.1*i)*cos(0.1*j)
#norm=matplotlib.colors.Normalize(0.995,1.0)
im1 = plt.imshow(array, cmap=cm.hot, origin='lower',clip_on=True,filternorm=1)
#im1.set_norm(norm)
plt.colorbar()
plt.savefig('test.png')
</code></pre>
https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?comment=18821#post-id-18821I will try.Tue, 23 Oct 2012 17:33:01 -0500https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?comment=18821#post-id-18821Answer by kcrisman for <p>Hi!</p>
<p>I would like to know if there is a way to get a colorbar for a density plot. For contour plots this works fine with the colorbar=True option, but for density plots there doesn't seem to be such an option. Can anyone help?</p>
<p>Greetings,
Melvin</p>
https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?answer=14182#post-id-14182This isn't built in, though [Trac 9150](http://trac.sagemath.org/sage_trac/ticket/9150) has been open for this for quite a while, and it probably wouldn't be too hard to put in.Tue, 23 Oct 2012 16:27:09 -0500https://ask.sagemath.org/question/9460/colorbar-for-density-plots/?answer=14182#post-id-14182