Changing Bar width of plotResiduals

1 visualización (últimos 30 días)
James Whitehouse
James Whitehouse el 17 de Abr. de 2020
Respondida: Ameer Hamza el 17 de Abr. de 2020
I'm using plotResiduals to plot the histogram graph, and am wondering if you can specify the width of the histrogram bars, or the number of them? I can't seem to find anything about specifying on the plotResiduals Help Center page.
Thanks

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 17 de Abr. de 2020
It is quite strange that mathwork has made it quite difficult to extract data out of plotResiduals function or plot. The following code shows one way. The following code shows one way to change the width of the bars by extracting the data from the plotResiduals figure and then creating a new figure using bar() function.
load carsmall
tbl = table(MPG,Weight);
tbl.Year = categorical(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');
p = plotResiduals(mdl);
vert = p.Vertices;
vert(1:5:end,:) = [];
hist_data = blockproc(vert, [4 2], @(x) mean(x.data(2:3,:)));
bar(hist_data(:,1), hist_data(:,2), 'BarWidth', 0.7);

Más respuestas (0)

Categorías

Más información sobre Graphics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by