Plotting image and data changes y-axis direction. Why and how to fi... (2025)

44 views (last 30 days)

Show older comments

Dhairya Mehta on 7 Jul 2022

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this

Answered: Steven Lord on 8 Jul 2022

  • borders.png
  • flipped.png

Open in MATLAB Online

I am plotting latitude and longitudes of locations in USA. Using borders, I can plot my coordinates without problems. However, when I try plotting my coordinates over an image, it changes the order of my y-axis from ascending to descending and my plots appear flipped on the x-axis. My code for plotting wanted_city and locations is the same when using borders function.

I tried using set() and it does not help.

set(gca,'YDir','reverse');

Why does it work with borders but not when being plotted over an image?

figure

% image of contiguous USA Koppen Climate, it is edited to be upside down,

image1 = imread('USA-KoppenClimate.png');

image([-124.7325 -66.9504],[24.5243 49.3560],flipud(image1)); %extreme [west east], [south, north] points for image placement

hold on

plot(wanted_city(2), wanted_city(1), 'k.', 'MarkerSize', 20); % plot(longitude, latitude, marker) of desired city

plot(locations(city(1),2), locations(city(1),1), 'r.', 'MarkerSize', 20); % plot(longitude, latitude, marker) of closest city

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (3)

Friedel Hartmann on 7 Jul 2022

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1002610

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1002610

Does the command

axis ij % makes the y axis point downward

placed after the plot command, help?

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Ramishetti sai sreeja on 8 Jul 2022

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1002825

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1002825

Hi Dhairya Mehta,

It is my understanding that the while plotting the cordinates on image the cordinates are being changed.

I assume you you gave the coordinates wrong,Refer to these ,

https://in.mathworks.com/matlabcentral/answers/225447-how-to-match-plot-and-image-coordinates

https://in.mathworks.com/matlabcentral/answers/269694-how-to-plot-some-points-on-an-image

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Steven Lord on 8 Jul 2022

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1003125

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/1755520-plotting-image-and-data-changes-y-axis-direction-why-and-how-to-fix-this#answer_1003125

From the "More About" section on the documentation page for the image function:

"The image function has two versions, the high-level version and the low-level version. If you use image with 'CData' as an input argument, then you are using the low-level version. Otherwise, you are using the high-level version.

The high-level version of image calls newplot before plotting and sets these axes properties:

  • Layer to 'top'. The image is shown in front of any tick marks or grid lines.
  • YDir to 'reverse'. Values along the y-axis increase from top to bottom. To decrease the values from top to bottom, set YDir to 'normal'. This setting reverses both the y-axis and the image.
  • View to [0 90].

The low-level version of the image function does not call newplot and does not set these axes properties."

The relevant piece of this information for your application is the second bullet that discusses the axes YDir property. You can:

  • change this property of the axes manually after you've called image (if you change it before, image will change it as part of its execution), or
  • you could call the low-level version of the image function, or
  • you could use the axis function with 'xy' as input. See the axis function documentation for more information on the 'xy' option
0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Image Processing and Computer VisionImage Processing ToolboxDisplay and ExplorationBasic Display

Find more on Basic Display in Help Center and File Exchange

Tags

  • axis
  • plot
  • image

Products

  • MATLAB

Release

R2022a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Plotting image and data changes y-axis direction. Why and how to fi... (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Plotting image and data changes y-axis direction. Why and how to fi... (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Mr. See Jast

Last Updated:

Views: 6015

Rating: 4.4 / 5 (55 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.