Owen Brandriss asked . 2023-06-12

How do I get smooth edges for a contourf plot on a log-log scale scatterplot?

Hello,
 
I am having some trouble with using the contourf function on a log-log scale plot. I have 9 datapoints in a 2D scatterplot that are colored for a third variable. The code I use to plot the data as well as the plot are included below.
 
a = reshape(mtot_1,1,[]); % convert matrix to row vector
b = reshape(MFR_1,1,[]); % convert matrix to row vector
c = reshape(SN_maxes_1,1,[]); % convert matrix to row vector
figure(4)
clf
hold on
scatter(b, a, [], c, 'filled') 
set(gca,'xscale','log')
set(gca,'yscale','log')
colorbar
xlabel('MFR')
ylabel('total mass flow')

a-contourf-plot-on-a-log-log-scale-scatterplot

As you can see, on a log-log scale, the datapoits form a sort of "skewed quadrilateral" shape with edges that look "straight" when plotted on log-log. I want to create a contour map from these 9 points, but when I do, it looks like the plot below because the contour is generated with a linear interpolation method that creates straight lines between the points on a normal linear axis scale, which then look distorted or curved when plotted on the log-log scale. I have also included the code I use.

figure(5)
clf
hold on
contourf(MFR_1, mtot_1, SN_maxes_1, 100, 'LineStyle', 'none') 
scatter(b, a, [], c, 'filled') 
set(gca,'xscale','log')
set(gca,'yscale','log')
d = colorbar;
d.Label.String = "Swirl No.";
xlabel('MFR')
ylabel('total mass flow')

a-contourf-plot-on-a-log-log-scale-scatterplot

I would like to make it so that the contour plot has "straight" edges between the outer datapoints when plotted on the log-log scale, so that the contour map essentially appears as a quadrilateral with straight sides on the log-log plot instead of the odd curvy shape in the contour plot above. Can someone please offer me some advice as to how to achieve this? Thanks in advance!

transform , plot , loglog , contour , MATLAB , Graphics

Expert Answer

John Michell answered . 2024-12-21 14:32:09

hello
 
I can suggest this , although I consider it needs some refinements
 
MFR_1 = [0.93016, 0.13933, 0.04154; 4.75072, 0.96454, 0.27638; 16.1767, 3.35929, 1.03684];
%Then the y-axis data (also a matrix): 
mtot_1 = [0.00087393, 0.001293, 0.00161739; 0.00146412, 0.00182395, 0.00211802; 0.00195069, 0.00228598, 0.002528465];
%Then the "z" data (if you would call it that). This is what determines the color of the dots.  It is also a matrix:
SN_maxes_1 = [1.678801, 1.627564, 1.521288; 1.535838, 1.848008, 1.7666569; 1.419559, 1.818278, 1.963394];
a = reshape(mtot_1,1,[]); % convert matrix to row vector
b = reshape(MFR_1,1,[]); % convert matrix to row vector
c = reshape(SN_maxes_1,1,[]); % convert matrix to row vector
figure(4)
clf
hold on
scatter(b, a, [], c, 'filled') 

% create a mesh with constant log spacing , and find points that are inside
% a polygon  (convex hull)
bl = log10(b');
al = log10(a');
cl = log10(c');
k = boundary(bl,al,1); % define outer hull 
xv = bl(k);
yv = al(k);
% plot(10.^xv, 10.^yv, '-r')

x = linspace(min(xv),max(xv),200);
y = linspace(min(yv),max(yv),200);
[X,Y] = meshgrid(x,y);
x = X(:);
y = Y(:);
in = inpolygon(x,y,xv,yv);
xin = 10.^(X(in));
yin = 10.^(Y(in));

vq = griddata(bl,al,c,log10(xin),log10(yin));
scatter(xin, yin, [], vq, 'filled') 
% plot(xin,yin,'.r')
set(gca,'xscale','log')
set(gca,'yscale','log')
colorbar
xlabel('MFR')
ylabel('total mass flow')
hold off

 

a-contourf-plot-on-a-log-log-scale-scatterplot


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.