How to flip an axis on a plot without affecting the plot? (2024)

function [x,y,u_avg,v_avg,CHC_tot] = piv_averages(prefix,suffix,Nstart,Nfinish,interp)

% This program reads in a series of instantaneous PIV vector fields from

% Insight and averages them. The user has the option of excluding

% interpolated vectors, which have CHC > 1. (interp = 0 means do not

% interpolate, while interp = 1 means interpolate).

% Create file name for each image

c_exit=3.007; %speed of sound

x0=1024; %origin of the jet in pixels

y0=53.8; %origin of the jetin pixels

D=923.71; %diameter of jet exit in pixels

v_shift=0;

for i = Nstart:Nfinish

Nstring = int2str(i); % Convert iteration number to a character string

if i < 10

filename_inst = strcat(prefix,'0000',Nstring,suffix);

elseif i < 100

filename_inst = strcat(prefix,'000',Nstring,suffix);

elseif i < 1000

filename_inst = strcat(prefix,'00',Nstring,suffix);

elseif i < 10000

filename_inst = strcat(prefix,'0',Nstring,suffix);

else

filename_inst = strcat(prefix,Nstring,suffix);

end

% Read file name

A_inst = csvread(filename_inst,1,0);

x = A_inst(:,1); % x-position (mm)

y = A_inst(:,2); % y-position (mm)

u = A_inst(:,3); % x-velocity (m/s)

v = A_inst(:,4); % y-velocity (m/s)

chc = A_inst(:,5); % number of good vectors at this location

N = size(x,1); % Length of entire vector array

% Initialize output variables if this is the first file

if i == Nstart

u_tot = zeros(N,1);

v_tot = zeros(N,1);

CHC_tot = zeros(N,1);

end

for j = 1:N

if interp == 0

if chc(j,1) == 1

u_tot(j,1) = u_tot(j,1) + u(j,1);

v_tot(j,1) = v_tot(j,1) + v(j,1);

CHC_tot(j,1) = CHC_tot(j,1) + 1;

end

elseif interp == 1

if chc(j,1) > 0

u_tot(j,1) = u_tot(j,1) + u(j,1);

v_tot(j,1) = v_tot(j,1) + v(j,1);

CHC_tot(j,1) = CHC_tot(j,1) + 1;

end

end

end

end

for j = 1:N

u_avg(j,1) = u_tot(j,1)/CHC_tot(j,1);

v_avg(j,1) = v_tot(j,1)/CHC_tot(j,1);

end

% Set origin to jet exit centerline

x_c = x - x0;

y_c = y - y0;

% Shift by convective velocity

v = v - v_shift;

% Nondimensionalize variables

x_non = x_c/D; % Nondimensionalize using jet diameter

y_non = y_c/D; % Nondimensionalize using jet diameter

u_non = u_avg/c_exit; % Nondimensionalize using sonic speed

v_non = v_avg/c_exit; % Nondimensionalize using sonic speed

%%%%%%%FOR H/D=2%%%%%%%%%

% 1) Choose a threshold

yThreshold = 400; %accept all vectors that start at or above y = yThreshold;

% 2) identify all quiver arrows that meet the criteria

acceptIdx = y >= yThreshold;

% 3) plot the quiver arrows, but only the ones accepted

figure(4)

quiver(x(acceptIdx), y(acceptIdx), u_avg(acceptIdx), v_avg(acceptIdx), 5)

% add reference line at threshold if you'd like

line(x,yThreshold);

% Plot nondimensional vector field

figure(2)

quiver(x_non(acceptIdx),y_non(acceptIdx),u_non(acceptIdx),v_non(acceptIdx),4)

axis([-1 1 0 2])

xticks([-1 0 1])

yticks([0 1 2])

set(gca,'YtickLabel',2:-1:0)

set(gca,'XAxisLocation','top','YAxisLocation','left');

xlabel('x/D')

ylabel('y/d')

title('Nondimensional velocity field')

% Plot averaged vector field

figure(1)

quiver(x(acceptIdx),y(acceptIdx),u_avg(acceptIdx),v_avg(acceptIdx),4)

axis([0 2000 0 2000])

set(gca,'YtickLabel',2000:-200:0)

set(gca,'XAxisLocation','top','YAxisLocation','left');

xlabel('z (pixels)')

ylabel('x (pixels)')

title('Dimensional velocity field')

% Plot averaged vector field

figure(3)

quiver(x(acceptIdx)/48.11,(y(acceptIdx)/48.11),u_avg(acceptIdx),v_avg(acceptIdx),4)

axis([0 42 0 42])

yticks([0 5 10 15 20 25 30 35 40])

set(gca,'XAxisLocation','top','YAxisLocation','left');

% set(gca,'ydir','reverse')

xlabel('z (mm)')

ylabel('x (mm)')

title('Dimensional velocity field')

% Output averaged data

output_avg = [x y u_avg v_avg CHC_tot];

dlmwrite('average_vels.dat','xyUVC');

dlmwrite('average_vels.dat',output_avg,'-append');

How to flip an axis on a plot without affecting the plot? (2024)

FAQs

How to flip the y-axis in Python? ›

To invert X-axis and Y-axis, we can use invert_xaxis() and invert_yaxis() function. We can invert either any one of the axes or both axes using the above methods. Code: Python3.

How do you remove the Y-axis in plot? ›

If we just want to turn either the X-axis or Y-axis off, we can use plt. xticks( ) or plt. yticks( ) method respectively.

What axis do you plot against? ›

The Axes. The independent variable belongs on the x-axis (horizontal line) of the graph and the dependent variable belongs on the y-axis (vertical line). The x and y axes cross at a point referred to as the origin, where the coordinates are (0,0).

How do you flip over the y-axis? ›

To reflect an equation over the y-axis, simply multiply the input variable by -1: y = f ( x ) → y = f ( − x ) .

How do you reverse the y-axis? ›

Select the y-axis on your Time chart. Switch to the Presentation properties tab and locate the Scale panel. Under 'Reverse' select 'Yes'.

How do you change the axis on a plot? ›

To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.

How do I change the y-axis in Matplotlib? ›

The simplest way to set the axis range in Matplotlib is by using the xlim() and ylim() functions. These functions allow you to define the minimum and maximum values that will be displayed on the X and Y axes, respectively. In the above example, we've set the X-axis to range from 0 to 5 and the Y-axis from 0 to 20.

How do you remove the y-axis from a chart? ›

Display or hide axes
  1. Click anywhere in the chart for which you want to display or hide axes. ...
  2. On the Design tab, click the down arrow next to Add chart elements, and then hover over Axes in the fly-out menu .
  3. Click the type of axis that you want to display or hide.

What does the y-axis tell us? ›

The y-axis shows you where a point is in the y (or vertical) direction on a Cartesian plane, a two-dimensional graph. It's also the starting (zero) point used to determine how far a point is along the x-axis. The y-intercept is where a line crosses the y-axis and where x = 0.

Is the y-axis vertical or horizontal? ›

The x and y-axis are two important lines of the coordinate plane. The x-axis is a horizontal number line and the y-axis is a vertical number line.

How do you change the y-axis in Python? ›

The simplest way to set the axis range in Matplotlib is by using the xlim() and ylim() functions. These functions allow you to define the minimum and maximum values that will be displayed on the X and Y axes, respectively. In the above example, we've set the X-axis to range from 0 to 5 and the Y-axis from 0 to 20.

How do you rotate the y-axis labels in Python? ›

There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax. set_xticklabels() and ax.

How do you log the y-axis in Python? ›

pyplot library can be used to change the y-axis scale to logarithmic. The method yscale() takes a single value as a parameter which is the type of conversion of the scale, to convert y-axes to logarithmic scale we pass the “log” keyword or the matplotlib. scale. LogScale class to the yscale method.

How do you flip a polynomial on the y-axis? ›

We can reflect the graph of y=f(x) over the x-axis by graphing y=-f(x) and over the y-axis by graphing y=f(-x).

Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6372

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.