plot(fit, 'Style', 'Contour') resolution when using larger grids?
Show older comments
I am trying to plot a fit as a contour plot in my application analog to the contour plot in the curvefitting toolbox but I am running into what seems to be a rendering issue when using larger grids as can be observed below.


In both images the same fit is plotted once in a small grid (clipped at the border of the fit location) once in the whole grid. I am looking for a more detailed plot of the contours due to the fact that there are multiple fits on oither locations in this grid I would like to plot in the same axis.
It seems the rendering of the contour levels is less detailed.
I tried to find documentation on the plot(..., 'Style', 'Contour') option but so far have not found much in the help of Matlab, nor the community forums.
I would like to have the same rendering quality of the contours in the full grid as the cropped grid. Any pointers on how to do so?
In order to be able to reproduce my example
%% Spanning grid: this is normally extracted from the data, but this is for easy reproducibility
[xg, yg] = meshgrid([-130:5:130], [-130:5:130]);
xyg = reshape([xg yg], [], 2);
%% Setup fit type and fit options
ft = fittype(...
'a*exp(-((x-b).^2/(2*c^2)+(y-d).^2/(2*e^2)))', ...
'independent', {'x', 'y'}, ...
'dependent', 'z' );
fitopts = fitoptions(...
'Method', 'NonlinearLeastSquares', ...
'Algorithm', 'Levenberg-Marquardt', ...
'Display', 'Off');
%% Create fit object for reproducability
% NOTE: This is normally done using actual 2d gaussian fit, but for reproducability this should be enough
% Arbitrary fit to allow us to assign our values for generation of spots
xt = 3 - 6 * rand( 49, 1 );
yt = 3 - 6 * rand( 49, 1 );
fitobj = fit([xt, yt], peaks(xt, yt), ft, fitopts);
% Set our fit outcome to created fit for demonstrative purposes
[fitobj.a, fitobj.b, fitobj.d, fitobj.c, fitobj.e] = ...
deal(1.400, 80.8763, -80.2487, 5.0000, 5.0000);
%% Determine indexes for current spot
indexes = yg > -100 & yg < -60 & xg > 60 & xg < 100;
% Read dosis from file (normally from DICOM file), for source see file attached to post
DOSE = readmatrix('dose.txt');
%% Plot
figure('Name', 'Plot fit in cropped grid', 'NumberTitle', 'off');
plot(fitobj, ...
xyg(indexes, :), ...
DOSE(indexes), ...
'Style', 'Contour');
axis equal tight
figure('Name', 'Plot fit in full grid', 'NumberTitle', 'off');
plot(fitobj, ...
xyg, ...
DOSE(:), ...
'Style', 'Contour')
axis equal tight
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!