bugGNU Octave - Bugs: bug #54747, Scatter plot error: number of...

 
 

bug #54747: Scatter plot error: number of colors in C must match number of points in X

Submitter:  avlas <kupiqu>
Submitted:  Thu 27 Sep 2018 08:27:27 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 28 Sep 2018 10:36:18 AM UTC, comment #8: 

Excellent, thank you.

avlas <kupiqu>
Fri 28 Sep 2018 12:08:18 AM UTC, comment #7: 

Okay, long term Octave should probably include the data too and just not plot it.  For the time being, however, I have modified scatter so that it doesn't plot NaN values and doesn't generate an error when you supply a color vector.  I applied this to the stable branch here (https://hg.savannah.gnu.org/hgweb/octave/rev/43998b5d910a).  It will be a part of any 4.4.2 bug fix release, or more likely the 5.0 release at the end of the year.

Since it is just an m-file, you can also download it from the Mercurial repository and replace the one in your distribution to see the fix.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Thu 27 Sep 2018 10:33:08 PM UTC, comment #6: 

So, it seems that Matlab (2018b) does not eliminate the nan value, but it doesn't use it.

avlas <kupiqu>
Thu 27 Sep 2018 10:29:59 PM UTC, comment #5: 

Sure


>> figure
>> x = [linspace(0,3*pi,100) nan linspace(0,3*pi,100)];
>> y = [cos(x) + rand(1,numel(x))];
>> sz = 80;
>> c = linspace(1,10,length(x));
>>
>> h = scatter(x,y,sz,c,'o','LineWidth',1.5);
>>
>> size (get (h, 'xdata'))

ans =

     1   201

>> size (get (h, 'cdata'))

ans =

     1   201


avlas <kupiqu>
Thu 27 Sep 2018 09:53:31 PM UTC, comment #4: 

That is interesting.  Not quite what I expected.  Could you run this new code sample?


figure
x = [linspace(0,3*pi,100) nan linspace(0,3*pi,100)];
y = [cos(x) + rand(1,numel(x))];
sz = 80;
c = linspace(1,10,length(x));

h = scatter(x,y,sz,c,'o','LineWidth',1.5);

size (get (h, 'xdata'))
size (get (h, 'cdata'))



Rik <rik5>
Group administrator
Thu 27 Sep 2018 08:55:01 PM UTC, comment #3: 

I see. Thank you.

Please see below:


figure
>> x = [linspace(0,3*pi,100) nan linspace(0,3*pi,100)];
>> y = [cos(x) + rand(1,numel(x))];
>> sz = 80;
>> c = linspace(1,10,length(x));
>>
>> h = scatter(x,y,sz,c,'o','LineWidth',1.5);
>> cdat = get (h, 'cdata');
>> cdat (98:102)

ans =

    5.3650    5.4100    5.4550    5.5000    5.5450

>> diff (ans)

ans =

    0.0450    0.0450    0.0450    0.0450


avlas <kupiqu>
Thu 27 Sep 2018 08:51:09 PM UTC, comment #2: 

The issue is that x and y both contain a value of NaN at position 101.  Scatter does not plot NaN values so it removes them from the data pool which only leaves 200 values, while the color vector 'c' is 201.

Can you test the following on Matlab?


figure
x = [linspace(0,3*pi,100) nan linspace(0,3*pi,100)];
y = [cos(x) + rand(1,numel(x))];
sz = 80;
c = linspace(1,10,length(x));

h = scatter(x,y,sz,c,'o','LineWidth',1.5);
cdat = get (h, 'cdata');
cdat (98:102)
diff (ans)


I have a possible solution but I would like to match Matlab behavior.

Rik <rik5>
Group administrator
Thu 27 Sep 2018 08:30:09 PM UTC, comment #1: 

please ignore "z" in the previous example, it was used only later in the script from where I extracted this code snippet

avlas <kupiqu>
Thu 27 Sep 2018 08:27:27 PM UTC, original submission:  


Even when the size of x and c are the same, I get this error. Please check the following example:


figure
x = [linspace(0,3*pi,100) nan linspace(0,3*pi,100)];
y = [cos(x) + rand(1,numel(x))];
z = [sin(x) + rand(1,numel(x))];

sz = 80;
c = linspace(1,10,length(x));

scatter(x,y,sz,c,'o','LineWidth',1.5)

error: scatter: number of colors in C must match number of points in X
error: called from
    __scatter__ at line 103 column 5
    scatter at line 86 column 10


avlas <kupiqu>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by kupiqu (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-09-28 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2018-09-27 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code