2

I am trying to a log-log plot of enter image description here

Somehow points disappear somehow I don't understand why: enter image description here

Code:

    fig = plt.figure();
    ax=plt.gca() 
    ax.scatter(x,y,c="blue",alpha=0.95,edgecolors='none')
    ax.set_yscale('log')
    ax.set_xscale('log')

Data:

    (Pdb) print x,y
    [29, 36, 8, 32, 11, 60, 16, 242, 36, 115, 5, 102, 3, 16, 71, 0, 0, 21, 347, 19, 12, 162, 11, 224, 20, 1, 14, 6, 3, 346, 73, 51, 42, 37, 251, 21, 100, 11, 53, 118, 82, 113, 21, 0, 42, 42, 105, 9, 96, 93, 39, 66, 66, 33, 354, 16, 602]
     `[310000, 150000, 70000, 30000, 50000, 150000, 2000, 12000, 2500, 10000, 12000, 500, 3000, 25000, 400, 2000, 15000, 30000, 150000, 4500, 1500, 10000, 60000, 50000, 15000, 30000, 3500, 4730, 3000, 30000, 70000, 15000, 80000, 85000, 2200]

Can I get the log scale values also. I want to compute correlation.

Abhishek Bhatia
  • 9,404
  • 26
  • 87
  • 142
  • 2
    Did you try `ax.set_xlim((1,1000))` ? – plonser Sep 10 '15 at 12:42
  • @plonser Thanks for the comment, but it doesn't it automatically set to lower and upper limits of x. How is it different for log scale. – Abhishek Bhatia Sep 10 '15 at 14:35
  • 1
    In an interactive shell (ipython) all your data shows on a xscale 10^0 to 10^3, y scale 10^2 to 10^6 – hpaulj Sep 10 '15 at 16:12
  • I also can't reproduce your example, I get the same as @hpaulj. Using IPython Notebook. – areuexperienced Sep 10 '15 at 16:31
  • I am using anaconda, it include IPython. That's weird! – Abhishek Bhatia Sep 10 '15 at 20:51
  • hey guyz please check edit again. X seems to have zero values, which results `log(0)=-inf` and it can't plot it! So, I shouldn't take `log(x)` right? – Abhishek Bhatia Sep 10 '15 at 21:16
  • 1
    If you have values at or below 0, avoid using the log, yes. But if you like and think it's useful, you could use the [symlog scale](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xscale) in matplotlib: it becomes linear near 0, and logarithmic further away from 0. –  Sep 10 '15 at 22:06
  • @Evert Thanks for advice!! In case, of scatterplot syslog would zero values at zero right? – Abhishek Bhatia Sep 10 '15 at 22:08

1 Answers1

1

If you have some data with either x=0 or y=0 you won't be able to print those points on a log-log-plot as log(0) is undefined. However, using:

ax.set_yscale('symlog')
ax.set_xscale('symlog')

will allow you to see points a x=0 or y=0. There's a good explanation of the abilities of 'symlog' here.

Community
  • 1
  • 1
Kevin Johnson
  • 593
  • 4
  • 9