Ask Your Question
2

Colorbar for density plots

asked 12 years ago

MelvinSmith gravatar image

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, Melvin

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

Shashank gravatar image

I 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')
Preview: (hide)
link

Comments

Want to take a stab at #9150?

kcrisman gravatar imagekcrisman ( 12 years ago )

I will try.

Shashank gravatar imageShashank ( 12 years ago )
0

answered 12 years ago

kcrisman gravatar image

updated 12 years ago

This isn't built in, though Trac 9150 has been open for this for quite a while, and it probably wouldn't be too hard to put in.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 821 times

Last updated: Oct 23 '12