Since you are new, let us show you how Trendy works.

Close-button

Zoom on my Cody classification

  • Created by: J.R.! Menzinger
  • Latest result: Plot created
  • Created on: 21 Oct 2013
  • Liked: 3 times

This is a kind of "zoom" of this plot #Top10 on Cody, focussed on my current position, over the last 30 days.

I was playing on the data and the visualazing possibilities.

Take a look on the code

;-)

J.R.!

Plot Image
%% %% %% %% %% %% %% %% %% %% %% %% %% %% %% %% %% %% 

% Top Players in Cody
%   time vector is: time1748
%   data vector is: data1748


%% actual data for the legend:
url = 'http://www.mathworks.com/matlabcentral/cody/players';
html = urlread(url);

nameStart = regexp(html, '<h2 class="full_name">','end')+1;

nameEnd = regexp(html, '</h2>','start')-1;


% for i =1:numel(nameStart)
for i =1:10
    % disp(html(nameStart(i):nameEnd(i)))
    st = html(nameStart(i):nameEnd(i));

    
    aux = regexp(st, 'players/(\d*)', 'tokens');
    data{i,1} = str2num(aux{1}{1}); % the IDS of the top players
 
    aux = regexp(st, '>(.*)<', 'tokens');
    data{i,2} = aux{1}{1}; % the NAMES of the top players

    aux = regexp(st, 'Score: (\d*)', 'tokens');
    data{i,3} = str2num(aux{1}{1}); % the SCORES of the top players

end

playerIdsTop10 = [data{:,1}];
playerNameTop10 = data(:,2);
playerScoreTop10 = [data{:,3}];

%% use only the data from the last XX days:
tDays = 30;
data1748 = data1748(end-(0:tDays+1),:);
time1748 = time1748(end-(0:tDays+1),:);


%% get the scores of each player:
playerIds = data1748(:,1:2:end)';
playerScores = data1748(:,2:2:end)';

allPlayers = unique(playerIds(:))';
nP = numel(allPlayers);
nT = numel(time1748); 
scores = nan(nT,nP);

allPlayers = [playerIdsTop10 allPlayers(~ismember(allPlayers,playerIdsTop10))];

for iP = 1:nP

    timeID = playerIds == allPlayers(iP);
    
    actualScore = playerScores(timeID);
    
    nAS = numel(actualScore);
    nS = size(scores,1);
    
    
    scores(any(timeID),iP) = actualScore;
    
end


%% Find JR:
idJR = find(playerIdsTop10 == 2255311) +[-1 0 1];

scores = scores(:,idJR);
playerNameTop10 = playerNameTop10(idJR);
playerScoreTop10 = playerScoreTop10(idJR);

playerNameTop10{1} = ['\fontsize{13}'    num2str(idJR(1), '#%02d') ' ' playerNameTop10{1} '  (' num2str(playerScoreTop10(1)) ' points)'];
playerNameTop10{2} = ['\fontsize{16}\bf' num2str(idJR(2), '#%02d') ' ' playerNameTop10{2} '  (' num2str(playerScoreTop10(2)) ' points)'];
playerNameTop10{3} = ['\fontsize{13}'    num2str(idJR(3), '#%02d') ' ' playerNameTop10{3} '  (' num2str(playerScoreTop10(3)) ' points)'];

%% Add actual value:

scores = [playerScoreTop10 ;  scores];
time1748 = [now ; time1748];


%% plot
figure('Position',[440   38   560   830], 'Menubar','none')

h = plot(time1748,scores, '-');
hold on
hO = plot(time1748(1),scores(1,:), 'o');
set(gca, 'XTick',flipud(time1748(1:7:end)))
datetick('x','dd mmm', 'keepticks')

grid on

cO = circshift(get(gcf, 'DefaultAxesColorOrder'), 1-idJR(1));
set(h, {'Color'},{cO(1,:) ; cO(2,:) ; cO(3,:)}) 
set(hO, {'Color'},{cO(1,:) ; cO(2,:) ; cO(3,:)})

set([h(1:3) ; hO], 'LineWidth',4, 'MarkerSize',15)
set(h(idJR>=8), 'LineStyle','--')

yTick = get(gca, 'YTick');
yTickLabel = cellstr(num2str(yTick'/1000, '%2.1fk'));

set(gca, 'XLim',[min(time1748) max(time1748)+2] , ...
    'YAxisLocation','right' , ...
    'YTickLabel',yTickLabel)

title('Classification for \bfJ.R.!\rm  on Cody', 'FontSize',16)
xlabel({'Last 30 days' ; ' ' }, 'FontSize',16)
ylabel('Score', 'FontSize',16)


leg = legend(playerNameTop10{:} , ...
    'Location','SouthOutside');


%% Differences:

hD = plot(time1748([2 end-2]),[playerScoreTop10 ; playerScoreTop10], ':');

set(hD, {'Color'},{cO(1,:) ; cO(2,:) ; cO(3,:)}) 


xL = get(gca, 'XLim');
yL = get(gca, 'YLim');
axPos = get(gca, 'Position');

annotation('doublearrow',...
    axPos(1)+axPos(3)*(      time1748(end-3)-xL(1))/diff(xL)*[1 1],...
    axPos(2)+axPos(4)*(playerScoreTop10(1:2)-yL(1))/diff(yL))
text(time1748(end-4),mean(playerScoreTop10(1:2)), ...
    ['\Delta = ' num2str(abs(diff(playerScoreTop10(1:2)))) ' points'],...
    'FontSize',12 , ...
    'EdgeColor','k', ...
    'BackgroundColor',[1 1 1]);

annotation('doublearrow',...
    axPos(1)+axPos(3)*(      time1748(end-3)-xL(1))/diff(xL)*[1 1],...
    axPos(2)+axPos(4)*(playerScoreTop10(2:3)-yL(1))/diff(yL))
text(time1748(end-4),mean(playerScoreTop10(2:3)), ...
    ['\Delta = ' num2str(abs(diff(playerScoreTop10(2:3)))) ' points'],...
    'FontSize',12 , ...
    'EdgeColor','k', ...
    'BackgroundColor',[1 1 1]);
Tags:

Add Tags


3 comments

Alfonso Nieto-Castanon about 1 year ago

Cool plot! (and very nice effects with html markup, annotations, ticklabels, etc.)

J.R.! Menzinger about 1 year ago

Thanks!! The only error is the position of the arrows, it isn't correct anymore since the figure is exported... On a PC works fine the code.

J.R.! Menzinger about 1 year ago

related to this plot I made another one: http://www.mathworks.com/matlabcentral/trendy/plots/1201

;-)