Skip to content

Commit

Permalink
Various small fixes
Browse files Browse the repository at this point in the history
- Improved graphic fixes for old matlab versions
- Updated geom_abline() , geom_vbline(), geom_hbline() functions
- Bug fixes
- Added missing documentation
  • Loading branch information
piermorel committed Apr 18, 2017
1 parent 258a4fa commit 3f15667
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 21 deletions.
36 changes: 26 additions & 10 deletions @gramm/draw.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
end
end

%There are bugs with the hardware openGL renderer in pre 2014b version,
%on Mac OS and Win the x and y axes become invisible and on
%Windows the patch objects behave strangely.
if ~obj(1).handle_graphics
if ismac
warning('Mac Pre-2014b version detected, forcing to ''Painters'' renderer to show axes lines. Use set(gcf,''Renderer'',''OpenGL'') to restore transparency')
if isprop(obj(1).parent,'Renderer')
set(obj(1).parent,'Renderer','Painters');
end
else
warning('Windows Pre-2014b version detected, forcing to software openGL which is less buggy')
opengl software
end
end

%Handle call of draw() on array of gramm objects by dividing the figure
%up and launching the individual draw functions of each object
Expand Down Expand Up @@ -1174,15 +1188,25 @@
%Set ablines, hlines and vlines (after axe properties in case the limits
%are changed there
if obj.abline.on
xl=get(ca,'xlim');
%xl=get(ca,'xlim');
for line_ind=1:length(obj.abline.intercept)
tmp_xl=[obj.var_lim.minx obj.var_lim.maxx];
tmp_extent=(tmp_xl(2)-tmp_xl(1))*obj.abline.extent(line_ind)/2;
xl=[mean(tmp_xl)-tmp_extent mean(tmp_xl)+tmp_extent];
if ~isnan(obj.abline.intercept(line_ind))
%abline
plot(xl,xl*obj.abline.slope(line_ind)+obj.abline.intercept(line_ind),obj.abline.style{line_ind},'Parent',ca);
else
if ~isnan(obj.abline.xintercept(line_ind))
%vline
yl=get(ca,'ylim');
%yl=get(ca,'ylim');
if obj.var_lim.miny == obj.var_lim.maxy %We are probably in a case where y wasn't provided (histogram or raster)
tmp_yl=[0 numel(temp_aes.x)]; %We scale y according to number of x elements
else
tmp_yl=[obj.var_lim.miny obj.var_lim.maxy];
end
tmp_extent=(tmp_yl(2)-tmp_yl(1))*obj.abline.extent(line_ind)/2;
yl=[mean(tmp_yl)-tmp_extent mean(tmp_yl)+tmp_extent];
plot([obj.abline.xintercept(line_ind) obj.abline.xintercept(line_ind)],yl,obj.abline.style{line_ind},'Parent',ca);
else
if ~isnan(obj.abline.yintercept(line_ind))
Expand Down Expand Up @@ -1232,14 +1256,6 @@
obj.results=[];
end

%There are bugs with the openGL renderer in pre 2014b version,
%on Mac OS and Win the x and y axes become invisible and on
%Windows the patch objects behave strangely. So we switch to
%painters renderer
if verLessThan('matlab','8.4')
warning('Pre-2014b version detected, forcing to ''Painters'' renderer which is less buggy. Use set(gcf,''Renderer'',''OpenGL'') to restore transparency')
set(gcf,'Renderer','Painters')
end

obj.updater.first_draw=false;
end
Expand Down
3 changes: 2 additions & 1 deletion @gramm/geom_abline.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
my_addParameter(p,'slope',1);
my_addParameter(p,'intercept',0);
my_addParameter(p,'style','k--');
my_addParameter(p,'extent',2);
parse(p,varargin{:});

for obj_ind=1:numel(obj)
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,p.Results.slope,p.Results.intercept,NaN,NaN,@(x)x,p.Results.style);
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,p.Results.slope,p.Results.intercept,NaN,NaN,@(x)x,p.Results.style,p.Results.extent);
end
end
3 changes: 2 additions & 1 deletion @gramm/geom_funline.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
p=inputParser;
my_addParameter(p,'fun',@(x)x);
my_addParameter(p,'style','k--');
my_addParameter(p,'extent',2);
parse(p,varargin{:});

for obj_ind=1:numel(obj)
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,NaN,NaN,p.Results.fun,p.Results.style);
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,NaN,NaN,p.Results.fun,p.Results.style,p.Results.extent);
end
end
3 changes: 2 additions & 1 deletion @gramm/geom_hline.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
p=inputParser;
my_addParameter(p,'yintercept',0);
my_addParameter(p,'style','k--');
my_addParameter(p,'extent',2);
parse(p,varargin{:});

for obj_ind=1:numel(obj)
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,NaN,p.Results.yintercept,@(x)x,p.Results.style);
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,NaN,p.Results.yintercept,@(x)x,p.Results.style,p.Results.extent);
end
end
4 changes: 2 additions & 2 deletions @gramm/geom_label.m
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function obj = geom_label(obj,varargin)
% geom_label Display data as labels
%
% Example syntax: gramm_object.geom_jitter('Color','auto','dodge',0.6)
% Example syntax: gramm_object.geom_label('Color','auto','dodge',0.6)
% Geom label displays text (provided as 'label' in the constructor call
% gramm()). At the X and Y locations provided in the constructor call.
% Appearance of the text can be customized with any text property given as
% 'name',value pair in the arguments. The color-related arguments
% ('Color','EdgeColor','BackgroundColor') can also be set to 'auto' in
% order for the corresponding element to be colored according the the
% colro groups provided in the constructor. geom_label() also accepts a
% color groups provided in the constructor. geom_label() also accepts a
% 'dodge' argument.


Expand Down
3 changes: 2 additions & 1 deletion @gramm/geom_vline.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
p=inputParser;
my_addParameter(p,'xintercept',0);
my_addParameter(p,'style','k--');
my_addParameter(p,'extent',2);
parse(p,varargin{:});

for obj_ind=1:numel(obj)
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,p.Results.xintercept,NaN,@(x)x,p.Results.style);
obj(obj_ind).abline=fill_abline(obj(obj_ind).abline,NaN,NaN,p.Results.xintercept,NaN,@(x)x,p.Results.style,p.Results.extent);
end
end
3 changes: 2 additions & 1 deletion @gramm/gramm.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
'xintercept',[],...
'yintercept',[],...
'style',[],...
'fun',[])
'fun',[],...
'extent',[])

datetick_params={} %cell containng datetick parameters
current_row %What is the currently drawn row of the subplot
Expand Down
1 change: 1 addition & 0 deletions @gramm/private/fill_abline.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ab.intercept(end+1:end+l)=shiftdim(varargin{2});
ab.xintercept(end+1:end+l)=shiftdim(varargin{3});
ab.yintercept(end+1:end+l)=shiftdim(varargin{4});
ab.extent(end+1:end+l)=shiftdim(varargin{7});

%Because of the constructor these are initialized as empty
%arrays
Expand Down
1 change: 1 addition & 0 deletions @gramm/set_text_options.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
%
% 'name',value pairs:
% 'base_size': Base text size, corresponds to axis ticks text size (default is 10)
% 'interpreter': 'none'(default), 'tex' or 'latex'
% 'label_scaling': Scaling of axis label sizes relative to base (default is 1)
% 'legend_scaling': Scaling of legend label sizes relative to base (default is 1)
% 'legend_title_scaling': Scaling of legend title sizes relative to base (default is 1.2)
Expand Down
13 changes: 11 additions & 2 deletions @gramm/stat_ellipse.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@
m=nanmean(r);
cv=nancov(r);

obj.results.ellipse{obj.result_ind,1}.mean=m;
obj.results.ellipse{obj.result_ind,1}.cv=cv;
obj.results.stat_ellipse{obj.result_ind,1}.mean=m;
obj.results.stat_ellipse{obj.result_ind,1}.cv=cv;
obj.results.stat_ellipse{obj.result_ind,1}.major_axis=[];
obj.results.stat_ellipse{obj.result_ind,1}.minor_axis=[];

conf_sphpoints=sphpoints;
conf_sphpoints.vertices=bsxfun(@plus,sqrtm(cv)*conf_sphpoints.vertices'*k(obj.stat_options.alpha),m')';
Expand All @@ -131,5 +133,12 @@
obj.results.stat_ellipse{obj.result_ind,1}.center_handle=center_hndl;
else
warning('Not enough points for ellipse')

obj.results.stat_ellipse{obj.result_ind,1}.mean=NaN;
obj.results.stat_ellipse{obj.result_ind,1}.cv=NaN;
obj.results.stat_ellipse{obj.result_ind,1}.major_axis=[];
obj.results.stat_ellipse{obj.result_ind,1}.minor_axis=[];
obj.results.stat_ellipse{obj.result_ind,1}.ellipse_handle=[];
obj.results.stat_ellipse{obj.result_ind,1}.center_handle=[];
end
end
13 changes: 11 additions & 2 deletions @gramm/stat_summary.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
% percentiles
% - '95percentile': display the median and 2.5 and 97.5
% percentiles
% - 'fitnormalci'
% - 'fitnormalci'
% - 'fitpoissonci'
% - 'fit95percentile'
% - 'fit95percentile'
% - @function : provide a the handle to a custom function that takes
% y values (as an n_repetitions x n_data_points matrix) and returns
% both the central value and the CI with a matrix [y_central ; yc_CI_low ; y_CI_high]
% (with y_central, and y_CIs being 1 x n_data_points arrays).
% Example that uses the trimmed mean instead of regular mean:
%
% custom_statfun = @(y)([trimmean(y,2.5);bootci(500,{@(ty)trimmean(ty,2.5),y},'alpha',0.05)]);
% gramm_object.stat_summary('type', custom_statfun)
%
% - 'geom':
% - 'line': displays a line that connects the central locations
% (mean,median)
Expand Down
Binary file modified gramm cheat sheet.pdf
Binary file not shown.

0 comments on commit 3f15667

Please sign in to comment.