Skip to content

docs - scatterhistogram, histogram2d #436

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

Closed
danton267 opened this issue Oct 22, 2021 · 2 comments
Closed

docs - scatterhistogram, histogram2d #436

danton267 opened this issue Oct 22, 2021 · 2 comments

Comments

@danton267
Copy link
Member

load carsmall
tbl = table(Horsepower,MPG,Cylinders);
s = scatterhistogram(tbl,'Horsepower','MPG', ...
    'GroupVariable','Cylinders','HistogramDisplayStyle','smooth', ...
    'LineStyle','-');

fig2plotly(gcf);

legend is not captured properly, there is an artifact histogram bar in the middle of the graph, and following error message is printed:

Index in position 1 exceeds array bounds.
We had trouble parsing the scatterhistogram object.
This trace might not render properly.

x0 = randn(100,1)./5. + 0.5;
y0 = randn(100,1)./5. + 0.5;
x1 = rand(50,1);
y1 = rand(50,1) + 1.0;

x = [x0; x1];
y = [y0; y1];

trace1 = struct(...
  'x', x0, ...
  'y', y0, ...
  'mode', 'markers', ...
  'marker', struct(...
    'symbol', 'circle', ...
    'opacity', 0.7), ...
  'type', 'scatter');

trace2 = struct(...
  'x', x1, ...
  'y', y1, ...
  'mode', 'markers', ...
  'marker', struct(...
    'symbol', 'square', ...
    'opacity', 0.7), ...
  'type', 'scatter');

trace3 = struct(...
  'x', x, ...
  'y', y, ...
  'type', 'histogram2d');

data = {trace1, trace2, trace3};

plotly(data);

Legend for two scatter categories is being overlayed by colorbar.

@danton267
Copy link
Member Author

x = 2*randn(1000,1)+2;
y = 5*randn(1000,1)+3;
h = histogram2(x,y,'DisplayStyle','tile','ShowEmptyBins','on');

fig2plotly(gcf);

is incorrectly plotted

gilbertogalvis pushed a commit that referenced this issue Oct 30, 2021
gilbertogalvis added a commit that referenced this issue Oct 30, 2021
@gilbertogalvis
Copy link
Contributor

This issue was fixed by PR #466

Example 1

load carsmall
tbl = table(Horsepower,MPG,Cylinders);
s = scatterhistogram(tbl,'Horsepower','MPG', ...
		  'GroupVariable','Cylinders','HistogramDisplayStyle','smooth', ...
		  'LineStyle','-');

fig2plotly(gcf);

Screen Shot 2021-10-29 at 8 45 17 PM

Example 2

x0 = randn(100,1)./5. + 0.5;
y0 = randn(100,1)./5. + 0.5;
x1 = rand(50,1);
y1 = rand(50,1) + 1.0;

x = [x0; x1];
y = [y0; y1];

trace1 = struct(...
  'x', x0, ...
  'y', y0, ...
  'mode', 'markers', ...
  'marker', struct(...
    'symbol', 'circle', ...
    'opacity', 0.7), ...
  'type', 'scatter');

trace2 = struct(...
  'x', x1, ...
  'y', y1, ...
  'mode', 'markers', ...
  'marker', struct(...
    'symbol', 'square', ...
    'opacity', 0.7), ...
  'type', 'scatter');

trace3 = struct(...
  'x', x, ...
  'y', y, ...
  'type', 'histogram2d');

data = {trace1, trace2, trace3};

plotly(data);

This particular issue is because you are not setting the layout for the legend (you are leaving it by default). Then plotly position the legend wherever (in this case under the colorbar)

To fix it, you only have to configure the legend in the layout struct, in such a way that you correctly specify its position (avoiding that it is below the colorbar).

For this, please use the following code

x0 = randn(100,1)./5. + 0.5;
y0 = randn(100,1)./5. + 0.5;
x1 = rand(50,1);
y1 = rand(50,1) + 1.0;

x = [x0; x1];
y = [y0; y1];

trace1 = struct(...
		'x', x0, ...
		'y', y0, ...
		'mode', 'markers', ...
		'marker', struct(...
		  'symbol', 'circle', ...
		  'opacity', 0.7), ...
		'type', 'scatter');

trace2 = struct(...
		'x', x1, ...
		'y', y1, ...
		'mode', 'markers', ...
		'marker', struct(...
		  'symbol', 'square', ...
		  'opacity', 0.7), ...
		'type', 'scatter');

trace3 = struct(...
		'x', x, ...
		'y', y, ...
		'type', 'histogram2d');

data = {trace1, trace2, trace3};

layout = struct(...
		  'legend', struct(...
		'y', 1.0, ...
		'yanchor', 'bottom', ...
		'x', 1.0, ...
		'xanchor', 'right'), ...
		  'xaxis', struct('zeroline', false), ...
		  'yaxis', struct('zeroline', false) ...
		  );

plotly(data, struct('layout', layout));

Screen Shot 2021-10-29 at 8 45 37 PM

Example 3

x = 2*randn(1000,1)+2;
y = 5*randn(1000,1)+3;
h = histogram2(x,y,'DisplayStyle','tile','ShowEmptyBins','on');

fig2plotly(gcf);

Screen Shot 2021-10-29 at 8 45 58 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants