Skip to content

Commit 1dd0644

Browse files
committed
Added stat_violin() for violin plots.
- Added stat_cornerhist() for corner histogram of the x-y difference (beta)
1 parent b1f4faa commit 1dd0644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+710
-67
lines changed

@gramm/draw.m

+9-3
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@
230230
%Get colormap
231231
cmap=get_colormap(length(uni_color),length(uni_lightness),obj.color_options);
232232

233+
%Initialize continuous colormap
234+
obj.continuous_color_colormap=pa_LCH2RGB([linspace(0,100,256)'...
235+
repmat(100,256,1)...
236+
linspace(30,90,256)']);
233237

234238
%Initialize results structure (n_groups is an overestimate if
235239
%there are redundant groups
@@ -275,6 +279,8 @@
275279
draw_data.dodge_avl_w=1;
276280
end
277281

282+
obj.data_size=numel(temp_aes.x);
283+
278284

279285
%% draw() looping
280286
%Loop over rows
@@ -867,7 +873,7 @@
867873
temp_xlim=[obj.plot_lim.minx(ind_row,ind_column) obj.plot_lim.maxx(ind_row,ind_column)];
868874
end
869875
if sum(isnan(temp_xlim))==0
870-
set(ca,'XLim',temp_xlim+[-diff(temp_xlim)*obj.xlim_extra*0.5 diff(temp_xlim)*obj.xlim_extra*0.5]);
876+
set(ca,'XLim',temp_xlim+[-diff(temp_xlim)*obj.xlim_extra(1) diff(temp_xlim)*obj.xlim_extra(2)]);
871877
end
872878

873879
switch temp_yscale
@@ -879,7 +885,7 @@
879885
temp_ylim=[obj.plot_lim.miny(ind_row,ind_column) obj.plot_lim.maxy(ind_row,ind_column)];
880886
end
881887
if sum(isnan(temp_ylim))==0
882-
set(ca,'YLim',temp_ylim+[-diff(temp_ylim)*obj.ylim_extra*0.5 diff(temp_ylim)*obj.ylim_extra*0.5]);
888+
set(ca,'YLim',temp_ylim+[-diff(temp_ylim)*obj.ylim_extra(1) diff(temp_ylim)*obj.ylim_extra(2)]);
883889
end
884890

885891
if ~isempty(temp_aes.z) %Only do the Z limit stuff if we have z data
@@ -890,7 +896,7 @@
890896
case 'per_plot'
891897
temp_zlim=[obj.plot_lim.minz(ind_row,ind_column) obj.plot_lim.maxz(ind_row,ind_column)];
892898
end
893-
set(ca,'ZLim',temp_zlim+[-diff(temp_zlim)*obj.zlim_extra*0.5 diff(temp_zlim)*obj.zlim_extra*0.5]);
899+
set(ca,'ZLim',temp_zlim+[-diff(temp_zlim)*obj.zlim_extra(1) diff(temp_zlim)*obj.zlim_extra(2)]);
894900

895901
%Always have ticks if we have z data
896902
has_xtick=true;

@gramm/gramm.m

+11-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
title_axe_handle %Store the handle of the title axis
88
facet_axes_handles %Stores the handles of the facet axes
99
results %Stores the results of the draw functions and statistics computations
10+
1011
end
1112

1213
properties (Access=protected,Hidden=true)
@@ -37,9 +38,9 @@
3738
%corresponding to the facets, used to set axis limits
3839
plot_lim
3940

40-
xlim_extra=0.1 %extend range of XLim (ratio of original XLim width)
41-
ylim_extra=0.1 %extend range of XLim (ratio of original YLim width)
42-
zlim_extra=0.1
41+
xlim_extra=[0.05 0.05] %extend range of XLim (ratio of original XLim width)
42+
ylim_extra=[0.05 0.05] %extend range of XLim (ratio of original YLim width)
43+
zlim_extra=[0.05 0.05]
4344

4445
%Structure containing polar-related parameters: is_polar stores
4546
%whether to display polar plots, is_polar_closed to set if the
@@ -84,10 +85,7 @@
8485

8586
continuous_color=false %Do we use continuous colors (rather than discrete)
8687

87-
%Store the continuous color colormap
88-
continuous_color_colormap=pa_LCH2RGB([linspace(0,100,256)'...
89-
repmat(100,256,1)...
90-
linspace(30,90,256)']);
88+
continuous_color_colormap=[];
9189

9290
%Store options for generating colors
9391
color_options =struct('lightness_range',[85 15],...
@@ -123,11 +121,15 @@
123121
title_text_handle=[] %Stores handle of title text object
124122

125123
redraw_cache=[] %Cache store for faster redraw() calls
124+
redraw_fun={};
126125

127126
parent=[]
128127

129128
handle_graphics
129+
data_size
130+
130131
extra %Store extra geom-specific info
132+
131133
end
132134

133135
methods (Access=public)
@@ -219,6 +221,8 @@
219221
obj=stat_bin2d(obj,varargin)
220222
obj=stat_density(obj,varargin)
221223
obj=stat_qq(obj,varargin)
224+
obj=stat_cornerhist(obj,varargin)
225+
obj=stat_violin(obj,varargin)
222226

223227
function obj=set_parent(obj,parent)
224228
obj.parent=parent;

@gramm/private/parse_fill.m

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function [ face_color , face_alpha , edge_color , edge_alpha ] = parse_fill (fill,color)
2+
3+
face_alpha=1;
4+
edge_alpha=0.8;
5+
switch fill
6+
case 'edge'
7+
edge_color=color;
8+
face_color=color;
9+
face_alpha=0;
10+
case 'face'
11+
edge_color='k';
12+
edge_alpha=1;
13+
face_color=color;
14+
case 'all'
15+
edge_color=color;
16+
edge_alpha=0;
17+
face_color=color;
18+
case 'transparent'
19+
edge_color=color;
20+
face_color=color;
21+
face_alpha=0.4;
22+
end
23+
24+
end
25+

@gramm/redraw.m

+7
Original file line numberDiff line numberDiff line change
@@ -410,5 +410,12 @@
410410
end
411411
end
412412

413+
414+
if ~isempty(obj.redraw_fun)
415+
for k=1:length(obj.redraw_fun)
416+
obj.redraw_fun{k}();
417+
end
418+
end
419+
413420
%inCallback = [];
414421
end

@gramm/set_limit_extra.m

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
function obj=set_limit_extra(obj,x_extra,y_extra,z_extra)
22
%set_limit_extra Add some breathing room around data in plots
33
%
4-
% Example syntax gramm_object.set_limit_extra(0.1,0.1)
4+
% Example syntax gramm_object.set_limit_extra([0.05 0.2],0.05)
55
% first argument is XLim extra, second is YLim extra, extra
6-
% room is expressed as ratio to original limits. 0.1 will
7-
% extend by 5% on each side.
6+
% room is expressed as ratio to original limits. It is possible to set
7+
% extra room separately for upper and lower limits by giving a 2x1 array.
8+
% If not, the lower and uupper limit extra will be the same
89

910
if nargin<4
1011
z_extra=0;
1112
end
1213

14+
%If only one element is given we use it for upper and lower extra
15+
if numel(x_extra==1)
16+
x_extra=[x_extra x_extra];
17+
end
18+
if numel(y_extra==1)
19+
y_extra=[y_extra y_extra];
20+
end
21+
if numel(z_extra==1)
22+
z_extra=[z_extra z_extra];
23+
end
24+
1325
for obj_ind=1:numel(obj)
1426
obj(obj_ind).xlim_extra=x_extra;
1527
obj(obj_ind).ylim_extra=y_extra;

@gramm/stat_bin.m

+2-20
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,8 @@
140140

141141

142142
%Set up colors according to fill
143-
face_alpha=1;
144-
edge_alpha=0.8;
145-
switch params.fill
146-
case 'edge'
147-
edge_color=draw_data.color;
148-
face_color=draw_data.color;
149-
face_alpha=0;
150-
case 'face'
151-
edge_color='k';
152-
edge_alpha=1;
153-
face_color=draw_data.color;
154-
case 'all'
155-
edge_color=draw_data.color;
156-
edge_alpha=0;
157-
face_color=draw_data.color;
158-
case 'transparent'
159-
edge_color=draw_data.color;
160-
face_color=draw_data.color;
161-
face_alpha=0.4;
162-
end
143+
[face_color , face_alpha , edge_color , edge_alpha] = parse_fill (params.fill,draw_data.color);
144+
163145

164146

165147

0 commit comments

Comments
 (0)