Skip to content

Improve scatter plot marker sizes (matlab measures in 'points' whereas plotly measures in pixels) #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 91 additions & 97 deletions plotly/plotlyfig_aux/helpers/extractLineMarker.m
Original file line number Diff line number Diff line change
@@ -1,121 +1,115 @@
function marker = extractLineMarker(line_data)
% EXTRACTS THE MARKER STYLE USED FOR MATLAB OBJECTS
% OF TYPE "LINE". THESE OBJECTS ARE USED IN LINESERIES,
% STAIRSERIES, STEMSERIES, BASELINESERIES, AND BOXPLOTS

% EXTRACTS THE MARKER STYLE USED FOR MATLAB OBJECTS
% OF TYPE "LINE". THESE OBJECTS ARE USED IN LINESERIES,
% STAIRSERIES, STEMSERIES, BASELINESERIES, AND BOXPLOTS
%---------------------------------------------------------------------%

%-------------------------------------------------------------------------%
%-INITIALIZE OUTPUT-%
marker = struct();

%-INITIALIZE OUTPUT-%
marker = struct();
%---------------------------------------------------------------------%

%-------------------------------------------------------------------------%
%-MARKER SIZE-%
marker.size = line_data.MarkerSize;

%-MARKER SIZE-%
marker.size = line_data.MarkerSize;

if length(marker.size) == 1
marker.size = 0.6*marker.size;
end

%-------------------------------------------------------------------------%

%-MARKER SYMBOL-%
if ~strcmp(line_data.Marker,'none')

switch line_data.Marker
case '.'
marksymbol = 'circle';
case 'o'
marksymbol = 'circle';
case 'x'
marksymbol = 'x-thin-open';
case '+'
marksymbol = 'cross-thin-open';
case '*'
marksymbol = 'asterisk-open';
case {'s','square'}
marksymbol = 'square';
case {'d','diamond'}
marksymbol = 'diamond';
case 'v'
marksymbol = 'triangle-down';
case '^'
marksymbol = 'triangle-up';
case '<'
marksymbol = 'triangle-left';
case '>'
marksymbol = 'triangle-right';
case {'p','pentagram'}
marksymbol = 'star';
case {'h','hexagram'}
marksymbol = 'hexagram';
if line_data.Marker == "." % scale factor for points is off
marker.size = floor(sqrt(marker.size));
elseif length(marker.size) == 1
marker.size = 0.6*marker.size;
end

marker.symbol = marksymbol;
if isfield(line_data, 'MarkerIndices')
marker.maxdisplayed=length(line_data.MarkerIndices)+1;
end
end

%-------------------------------------------------------------------------%
%---------------------------------------------------------------------%

%-MARKER SYMBOL-%
if ~strcmp(line_data.Marker,"none")
switch line_data.Marker
case "."
marksymbol = "circle";
case "o"
marksymbol = "circle";
case "x"
marksymbol = "x-thin-open";
case "+"
marksymbol = "cross-thin-open";
case "*"
marksymbol = "asterisk-open";
case {"s","square"}
marksymbol = "square";
case {"d","diamond"}
marksymbol = "diamond";
case "v"
marksymbol = "triangle-down";
case "^"
marksymbol = "triangle-up";
case "<"
marksymbol = "triangle-left";
case ">"
marksymbol = "triangle-right";
case {"p","pentagram"}
marksymbol = "star";
case {"h","hexagram"}
marksymbol = "hexagram";
end
marker.symbol = marksymbol;
if isfield(line_data, "MarkerIndices")
marker.maxdisplayed=length(line_data.MarkerIndices)+1;
end
end

%-MARKER LINE WIDTH-%
marker.line.width = line_data.LineWidth;
%---------------------------------------------------------------------%

%-------------------------------------------------------------------------%
%-MARKER LINE WIDTH-%
marker.line.width = line_data.LineWidth;

filledMarkerSet = {'o','square','s','diamond','d',...
'v','^', '<','>','hexagram','pentagram'};
%---------------------------------------------------------------------%

filledMarker = ismember(line_data.Marker,filledMarkerSet);
filledMarkerSet = {"o","square","s","diamond","d",...
"v","^", "<",">","hexagram","pentagram"};

%-------------------------------------------------------------------------%
filledMarker = ismember(line_data.Marker,filledMarkerSet);

%--MARKER FILL COLOR--%
%---------------------------------------------------------------------%

MarkerColor = line_data.MarkerFaceColor;
%--MARKER FILL COLOR--%
MarkerColor = line_data.MarkerFaceColor;

if filledMarker
if isnumeric(MarkerColor)
col = 255*MarkerColor;
markercolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
else
switch MarkerColor
case 'none'
markercolor = 'rgba(0,0,0,0)';
case 'auto'
markercolor = 'rgba(0, 0.4470, 0.7410,1)';
if filledMarker
if isnumeric(MarkerColor)
col = 255*MarkerColor;
markercolor = sprintf("rgb(%d,%d,%d)", col);
else
switch MarkerColor
case "none"
markercolor = "rgba(0,0,0,0)";
case "auto"
markercolor = "rgba(0, 0.4470, 0.7410,1)";
end
end
marker.color = markercolor;
end

marker.color = markercolor;

end

%-------------------------------------------------------------------------%

%-MARKER LINE COLOR-%
%---------------------------------------------------------------------%

MarkerLineColor = line_data.MarkerEdgeColor;
%-MARKER LINE COLOR-%
MarkerLineColor = line_data.MarkerEdgeColor;

if isnumeric(MarkerLineColor)
col = 255*MarkerLineColor;
markerlinecolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
else
switch MarkerLineColor
case 'none'
markerlinecolor = 'rgba(0,0,0,0)';
case 'auto'
col = 255*line_data.Color;
markerlinecolor = ['rgb(' num2str(col(1)) ',' num2str(col(2)) ',' num2str(col(3)) ')'];
if isnumeric(MarkerLineColor)
col = 255*MarkerLineColor;
markerlinecolor = sprintf("rgb(%d,%d,%d)", col);
else
switch MarkerLineColor
case "none"
markerlinecolor = "rgba(0,0,0,0)";
case "auto"
col = 255*line_data.Color;
markerlinecolor = sprintf("rgb(%d,%d,%d)", col);
end
end
end

if filledMarker
marker.line.color = markerlinecolor;
else
marker.color = markerlinecolor;
if filledMarker
marker.line.color = markerlinecolor;
else
marker.color = markerlinecolor;
end
end

end