histogram on data graph

6 views (last 30 days)
Eli
Eli on 24 Mar 2024
Edited: Star Strider on 30 Mar 2024
Hi,
I have a graph i plot as
plot(x,y). it looks like this:
I want to make it a histogram like this:
both the inner colors as you see correspond to the histogram, and also the histogram on the right side of each graph.
How can i do it?

Accepted Answer

Star Strider
Star Strider on 24 Mar 2024
One option (if your data were a scatter plot) would be the scatterhist or scatterhistogram functions.
Otherwise, perhaps something like this —
x = linspace(0, 100, 1000);
y = randn(size(x));
pd = fitdist(y(:), 'normal');
xd = linspace(min(y), max(y), 250);
yd = pdf(pd, xd);
figure
tiledlayout(1,3, 'TileSpacing','none')
nexttile([1 2])
plot(x, y)
nexttile
plot(yd,xd)
Ax3 = gca;
Ax3.XTick = [];
Ax3.YTick = [];
Experiment to get the result you want.
.
  14 Comments
Eli
Eli on 30 Mar 2024
Edited: Eli on 30 Mar 2024
I found a way with it. it's not the best, but still it works.
using:
print('-vector','-depsc','myVectorFile')
And than need to insert EPS file to inkspace accoring to :
it's not the perfect solution, but it's good enough for now.
Star Strider
Star Strider on 30 Mar 2024
Edited: Star Strider on 30 Mar 2024
O.K.
I don’t have any experience with vector graphics. It’s never been something I needed to understand.
I just knew that the print function can save graphics objects in a variety of formats, so I suggested it.
Another option that I jjust now thought of is the exportgraphics function. (Again, I have no experience with it.)
EDIT — (30 Mar 2024 at 10:32)
I’m glad you found a solution. It’s difficult to help you because you never share your code or data, so I’m left guessing. I won’t from here on. Good luck with your projects!
.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots 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!