How to plot a dot as a sphere like those in OriginLab?

15 visualizzazioni (ultimi 30 giorni)
As shown below, in Origin one can choose the dot shape as a sphere which looks like a solid, fancy! So how can Matlab also do this? Thanks!

Risposta accettata

DGM
DGM il 20 Apr 2022
Modificato: DGM il 20 Apr 2022
There isn't such an option for plot() or scatter() objects:
But there may be some workarounds.
You could sort of fake a highlight like so:
x = linspace(0,1,10);
y = x.^2;
% plot the lines
plot(x,y,'k'); hold on
% plot the markers
scatter(x,y,50,'k','filled')
scatter(x-0.005,y(1,:)+0.005,10,'w','filled')
xlim([-0.01 1])
ylim([0 1.01])
Or you could do it the expensive way and make actual spheres
clf
x = linspace(0,1,10);
y = x.^2;
% plot the lines
plot(x,y,'k'); hold on
% plot the markers
scale = 0.015;
[xx yy zz] = sphere(20);
xx = xx*scale;
yy = yy*scale;
zz = zz*scale;
for k = 1:numel(x)
surf(xx+x(k),yy+y(k),zz)
end
shading flat
colormap([1 1 1]*0.7)
lightangle(gca,-135,45)
lighting gouraud
material([0.3 1 1])
xlim([-0.01 1])
ylim([0 1.01])
You could also create any small image and place copies of it as markers. Note the use of transparency and the fact that the marker will appear upside-down.
clf
x = linspace(0,1,10);
y = x.^2;
% plot the lines
plot(x,y,'k'); hold on
% place actual marker images
[mk,~,alph] = imread('sphmarker.png'); % sphere
%[mk,~,alph] = imread('sphmarker2.png'); % smiley
markerrad = 0.015;
for k = 1:numel(x)
im = imagesc(x(k)+[-1 1]*markerrad,y(k)+[-1 1]*markerrad,mk);
im.AlphaData = alph;
end
You might also be able to look an the FEX and see if someone has a solution that would work.
  2 Commenti
chris shen
chris shen il 20 Apr 2022
Btw Matlab really should improve the ability of plotting. Otherwise how can it compete with Python?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by