2

I have a scatter plot with the points shaded according to a third variable. I want to use a symmetric logarithmic scale for my colormap as described in the api: SymLogNorm

Unfortunately I get the following error:

TypeError: array cannot be safely cast to required type

Here a mini example. I'm using matplotlib 1.3.0.

# loading modules
import matplotlib as mpl
import matplotlib.pyplot as plt

# defining variables
x=[0,1,2,3]
y=[0,1,2,3]
c=[-1000,-100,100,1000]

# making scatterplot

plt.scatter(x, y, c=c, norm=mpl.colors.SymLogNorm(linthresh=10))

Without the symmetric logarithmic colormap the plot works fine.

plt.scatter(x, y, c=c)

see here

Thank you very much for your help.

3
  • 1
    What version of matplotlib are you using? Your "broken" example works for me with 1.3.0. Oct 8, 2013 at 9:55
  • I'm using 1.3.0. So I don't understand why it is not working.
    – Chris
    Oct 8, 2013 at 11:41
  • Did you try with above example? Oct 8, 2013 at 12:00

1 Answer 1

2

The documentation for SymLogNorm is not particularly clear, as a result I am not confident everything I say in this answer is correct. It seems the vmin and vmax arguments should be used to determine the range of data your consider e.g:

# loading modules
import matplotlib as mpl
import matplotlib.pyplot as plt

# defining variables
x=[0,1,2,3]
y=[0,1,2,3]
c=[-1000,-100,100,1000]

# making scatterplot
plt.scatter(x, y, c=c, s=100, norm=mpl.colors.SymLogNorm(linthresh=10, vmin=-1e3, vmax=1e3))
plt.colorbar(ticks=c)

enter image description here

The colorbar ticks are then not going to know that it is log scaled but I think this is the effect you were aiming for.

1
  • Thanks a lot for the help! Actually the arguments vmin and vmax are needed to make SymLogNorm work. It should be written somewhere in the documentation.
    – Chris
    Oct 8, 2013 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.