Hello, I am trying to plot data on a scatterhistogram, figure attached. The y axis comes out squished - as it goes up to 350 while the data peaks at 100. I can't figure out how to limit it to 100 instead of 350. I succeeded in getting a popup in the live editor which allowed me to delete ticks from the y axis, but I can't find it again and I didn't copy the code. Thank you for your help.

댓글 수: 10

Adam Danz
Adam Danz 2020년 8월 28일
Please provide a minimal working example that reproduces the problem.
The y axis labels look suspicious to me and the main axis is typically set to "tight" which would greately reduce your y-axis limits so something seems off and it may be user error.
AM
AM 2020년 8월 28일
I'm sure it's user error, I'm just learning. What do you mean "minimum working example"?
Adam Danz
Adam Danz 2020년 8월 28일
No problem. You've come to the right place!
A minimal working example is a short, concise block of code that we can copy/paste in order to reproduce the problem in our end. Sometimes that may require attaching a data file or including a few lines of code of "fake data". The points it to provide something that we can very simply copy/paste and immediately see the problem.
Thanks a lot! So this is the code I used, and I've attached the data (it is a publicly available excel spreadsheet)
youngpopulation = youngpopulation(youngpopulation.region == 'מחוז חיפה',:);
weekly_cases = sortrows(youngpopulation,'weekly_cases','descend')
age_date = weekly_cases(:, ["age_group", "last_week_day", "weekly_cases"])
scatter = scatterhistogram(age_date.last_week_day,age_date.weekly_cases,'GroupData',age_date.age_group);
Adam Danz
Adam Danz 2020년 8월 28일
편집: Adam Danz 2020년 8월 28일
The y axis is as expected when I run your code. Are you sure you're not making any adjustments after the plot is produced?
Two things I noticed:
  1. age_date.weekly_cases is categorical and it's plotted along the y axis. This is why you have so many y-tick labels. Since the categories are numeric, you probably want to convert those values to numbers. The plot would make more sense and it would look a lot better.
  2. One of the categories is "<15". If you take my advices in the first point above, you'll need to convert this category to some number (14?). The row of dots at the top of the plot below are data for this category and they will then appear at y=14 (or whatever value you choose). You can then indicate with text that this value is actually <=14.
Lastly, avoid using the variable name "scatter" since that's a commonly used Matlab function name.
AM
AM 2020년 8월 28일
Thank you very much! I changed this column to double and now the scatterhistogram shows properly, but <15 has been converted to NANs. How do I replace the NANs with, say 10?
x(isnan(x)) = 10
age_date(isnan(age_date)) = 10;
When I try this code (above) I get the following error:
Check for missing argument or incorrect argument data type in call to function 'isnan'.
Thank you for your patience!
Adam Danz
Adam Danz 2020년 8월 28일
This is after you've converted from categorical to numeric, right?
AM
AM 2020년 8월 28일
Right, I changed it to "double".

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2020년 8월 28일
이동: Adam Danz 2025년 4월 2일

0 개 추천

The variable name is throwing me off.
In your previous comments, age_date is a table with a last_week_day column which is datetime and a weekly_cases column which is categorical.
You should be converting the age_date.weekly_cases to numeric (not the whole table) and then replacing the NaN values within that column only.
If that doesn't solve the problem, please share a representitive sample of the variables with the NaN values.

댓글 수: 2

AM
AM 2020년 8월 28일
이동: Adam Danz 2025년 4월 2일
This fixed it. Thanks again!!
Adam Danz
Adam Danz 2020년 8월 28일
이동: Adam Danz 2025년 4월 2일
Socially-distant high five! The plot looks much better now. Don't forget to indicate somewhere that values at y=10 actually represent values that are less than 15.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

AM
2020년 8월 28일

이동:

2025년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by