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

11 ビュー (過去 30 日間)
chris shen
chris shen 2022 年 4 月 19 日
コメント済み: chris shen 2022 年 4 月 20 日
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!

採用された回答

DGM
DGM 2022 年 4 月 20 日
編集済み: DGM 2022 年 4 月 20 日
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 件のコメント
chris shen
chris shen 2022 年 4 月 20 日
Super!
chris shen
chris shen 2022 年 4 月 20 日
Btw Matlab really should improve the ability of plotting. Otherwise how can it compete with Python?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by