logo
down
shadow

How to limit the contour plot with a line plot?


How to limit the contour plot with a line plot?

By : MQMQ
Date : October 23 2020, 08:10 AM
seems to work fine I'm not sure you can achieve this with an already existing function.
What you can do is run a check on all the points of the grid and, if y is over the limit defined by h you nan the X,Y,Z values:
code :
x0 = 0
dx = 4.5
for n1, xv in enumerate( X):
    for n2, x in enumerate( xv):
        index = (x - x0) / dx
        i1, i0 = int(np.ceil( index)), int(np.floor( index))
        y = (h[i1][1] - h[i0][1]) / dx * (x - h[i0][0]) + h[i0][1]
        if Y[n1][n2] > y:
            X[n1][n2] = np.nan
            Y[n1][n2] = np.nan
            Z[n1][n2] = np.nan
from scipy.interpolate import griddata 
import numpy as np 
import matplotlib.pyplot as plt 


M = np.array([[0.000000,1217.000000,594.503284],
    [4.500000,1183.886353,2099.999905],
    [9.000000,1220.000000,1071.599126],
    [13.500000,1184.565430,2099.999905],
    [18.000000,1219.000000,435.631812],
    [22.500000,1185.150635,2099.999905],
    [24.500000,1217.555542,320.541441],
    [27.000000,1185.427490,2099.999905],
    [31.500000,1216.000000,300.000012],
    [36.000000,1185.981445,2099.999905],
    [40.500000,1215.000000,306.778669],
    [45.000000,1186.629272,2099.999905],
    [49.500000,1216.000000,300.000012],
    [54.000000,1187.214478,2099.999905],
    [58.500000,1215.000000,300.000012],
    [63.000000,1187.893555,2099.999905],
    [67.500000,1218.000000,335.902870],
    [72.000000,1188.572510,2099.999905],
    [76.500000,1220.000000,359.615386],
    [81.000000,1189.282715,2099.999905],
    [85.500000,1224.000000,1382.480264],
    [90.000000,1189.992920,2099.999905],
    [94.500000,1225.000000,1206.023455],
    [99.000000,1190.578125,2099.999905]])

    #upper,limit
h = np.array([[0.0,1217],
    [4.5,1217],
    [9.0,1220],
    [13.5,1219],
    [18.0,1219],
    [22.5,1218],
    [27.0,1217],
    [31.5,1216],
    [36.0,1215],
    [40.5,1215],
    [45.0,1216],
    [49.5,1216],
    [54.0,1215],
    [58.5,1215],
    [63.0,1217],
    [67.5,1218],
    [72.0,1219],
    [76.5,1220],
    [81.0,1222],
    [85.5,1224],
    [90.0,1225],
    [94.5,1225],
    [99.0,1224],
    [103.5,1225]])
##
x=M[:,0] 
y=M[:,1]
z=M[:,2]
##  

xi=np.linspace(0,100.,100.) 
yi=np.linspace(1190,1225.,1225.) 
X,Y= np.meshgrid(xi,yi) 
Z = griddata((x, y), z, (X, Y),method='cubic') 

x0 = 0
dx = 4.5
for n1, xv in enumerate( X):
    for n2, x in enumerate( xv):
        index = (x - x0) / dx
        i1, i0 = int(np.ceil( index)), int(np.floor( index))
        y = (h[i1][1] - h[i0][1]) / dx * (x - h[i0][0]) + h[i0][1]
        if Y[n1][n2] > y:
            X[n1][n2] = np.nan
            Y[n1][n2] = np.nan
            Z[n1][n2] = np.nan

plt.contourf(X,Y,Z)
plt.colorbar()
plt.plot(h[:,0],h[:,1],'black',linewidth=2)
plt.scatter(x,y,marker ='o',c='k',s=10,zorder=10)
plt.xlim(0,100)
plt.ylim(1190,1225)
plt.grid(True)
plt.rc('grid',linestyle="-",color='black')
plt.show()


Share : facebook icon twitter icon
How can I make a contour plot doesn't overlap on the line plot in one axes?

How can I make a contour plot doesn't overlap on the line plot in one axes?


By : David Blanchard
Date : March 29 2020, 07:55 AM
like below fixes the issue in what order are you executing the above codes ? I first executed second code then the first code and this is my output
Here is the whole code I executed, I had to remove the line handle.axis2; as it was throwing an error.( I am using matlab 2011)
code :
close all
xMove = 3;
yMove = 10;
r = 30;  
rx = -r:0.1:r;
ry = r:-0.1:-r;
[x_coor, y_coor] = meshgrid(rx, ry);
radius = sqrt(x_coor.^2+y_coor.^2);
contourf(x_coor + xMove, y_coor + yMove, radius,'edgecolor','none');
xlabel('Widht');
ylabel('Long');
axis([0 30 0 30]);
colorbar;
caxis([0 10]);
grid on;
set(gca,'layer','top');
hold on;
% X
for i = 1.5:7;
    cur_x = i * 3.8;
    line([cur_x, cur_x], [0 5], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y
for i = 2:7;
    cur_y = i * 4;
    line([0 4],[cur_y, cur_y], 'color', 'r', 'LineWidth', 1.5);
    drawnow;  
end;

% X2
for i = 1.5:7;
    cur_x2 = i * 3.8;
    line([cur_x2, cur_x2], [25 31], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% Y2
for i = 1:8;
    cur_y2 = i * 3.5;
    line([26 31],[cur_y2, cur_y2], 'color', 'r', 'LineWidth', 1.5);
    drawnow;
end;

% X
line( [5.7 cur_x], [5 5], 'color', 'r', 'LineWidth', 1.5);

% Y
line( [4 4], [8 cur_y], 'color', 'r', 'LineWidth', 1.5);

% X2
line( [5.6 cur_x2], [25 25], 'color', 'r', 'LineWidth', 1.5);

% Y2
line( [26 26], [3.5 cur_y2], 'color', 'r', 'LineWidth', 1.5);


grid on;

axis([0 30 0 30]);
hold off;
Aligning contour line with contour filled plot irregular grid polar plot (semi circle)

Aligning contour line with contour filled plot irregular grid polar plot (semi circle)


By : Agilan Nandhakumar
Date : March 29 2020, 07:55 AM
Any of those help The contours and colours do not align because filled.contour produces two plots (legend and contour). After plotting, these coordinate systems are lost. (?filled.contour). This can be solved by adding the relevant commands to the plot.axes argument. Semi-circles can be drawn with draw.arc from the plotrix package, spokes with segments. The zone within a minimum radius can be covered by white segments to represent no data.
code :
# min distance of contours lines from center
min_dist=5

# position of spokes (degrees)
spk = seq(0,180,30)

filled.contour(x = fld$x,
               y = fld$y,
               z = fld$z,
               color.palette = colorRampPalette(c("white", "blue")),
               xlab = "",
               ylab = "",
               main = "Max",
               key.title = title(main = "Value", cex.main = 1),
               asp=1, xlim=c(0,40), ylim=c(-30,30),   frame.plot=F,
               plot.axes = {contour(fld$x, fld$y, fld$z , add=T, levels = seq(0,max(fld$z, na.rm=T),30), drawlabels=F, col=2);
                            # semi circles
                            draw.arc(x=0,y=0,radius = (1:3)*10, deg1=90, deg2=-90, col='grey');
                            # cover zone within minimum radius with (draw many closely spaced white lines
                            segments(x0 = 0, y0 = 0, x1 = sin((0:180)*pi/180)*min_dist, y1 = cos((0:180)*pi/180)*min_dist, col='white');
                            # spokes with labels
                            segments(x0 = 0, y0 = 0, x1 = sin(spk*pi/180)*30, y1 = cos(spk*pi/180)*30, col='grey');
                            text(x = sin(spk*pi/180)*30, y=cos(spk*pi/180)*30, labels = spk, pos=4, cex=0.6, xpd=NA)
                            # data points
                            points(x,y, pch=16, cex=0.6);
                            # x axis
                            axis(1);
                            # modified y axis
                            axis(2, at = axisTicks(range(y), log=F), labels = abs(axisTicks(range(y), log=F)), pos = 0);
               }
)
Plot dashed line interrupted with data (similar to contour plot)

Plot dashed line interrupted with data (similar to contour plot)


By : steaküberFluss
Date : March 29 2020, 07:55 AM
To fix the issue you can do I am stuck with a (hopefully) simple problem. My aim is to plot a dashed line interrupted with data (not only text). , Quick and dirty answer using annotate:
code :
import matplotlib.pyplot as plt
import numpy as np

x = list(reversed([1.81,1.715,1.78,1.613,1.629,1.714,1.62,1.738,1.495,1.669,1.57,1.877,1.385]))
y = [0.924,0.915,0.914,0.91,0.909,0.905,0.905,0.893,0.886,0.881,0.873,0.873,0.844]

def plot_with_text(x, y, text, text_count=None):
    text_count = (2 * (len(x) / len(text))) if text_count is None else text_count
    fig, ax = plt.subplots(1,1)
    l, = ax.plot(x,y)
    text_size = len(text) * 10
    idx_step = len(x) / text_count
    for idx_num in range(text_count):
        idx = int(idx_num * idx_step)
        text_pos = [x[idx], y[idx]]
        xscreen = ax.transData.transform(zip(x[max(0, idx-1):min(len(x), idx+2)], y[max(0, idx-1):min(len(y), idx+2)]))
        a = np.abs(np.gradient(xscreen)[0][0])
        rot = np.rad2deg(np.arctan2(*a)) - 90
        ax.annotate(text, xy=text_pos, color="r", bbox=dict(ec="1", fc="1", alpha=0.9), rotation=rot, ha="center", va="center")

plot_with_text(x, y, "test")
Overlay the data points which make-up a contour plot matrix on the same plot in MATLAB

Overlay the data points which make-up a contour plot matrix on the same plot in MATLAB


By : Patrik Jaš
Date : March 29 2020, 07:55 AM
Hope that helps Hope the title gave an adequate description of my problem. Basically, I am generating a contour plot in MATLAB using the contourf (x,y,z) function, where x and y are vectors of different lengths and z is a matrix of data with dimensions of x times y. The contourf plot is fine, however, I am looking to overlay this plot with the actual data points from the matrix z. I have tried using the scatter function, but I am getting an error message informing me that X and Y must be vectors of the same length - which they're not. Is there any other way to achieve this? , I think meshgrid should help you.
code :
z = peaks;               %// example 49x49 z data
x = 1:20;
y = 1:49;
z = z(y,x);              %// make dimensions not equal so length(x)~=length(y)
[c,h] = contourf(x,y,z); 
clabel(c,h); colorbar; 

[xx,yy]=meshgrid(x,y);   %// this is what you need
hold on;
plot(xx,yy,'k.');        %// overlay points on contourf
How to change the x axis limit in a Contour plot?

How to change the x axis limit in a Contour plot?


By : user3032572
Date : March 29 2020, 07:55 AM
To fix this issue If you use a subplot you need to use ax.set_xlim() or you can use plt.xlim() for a single plot with the documentation here.
For a subplot:
code :
ax = plt.subplot(111)
ax.contourf(x1, x2, data[::-1])
ax.set_xlim(right=7000)
plt.contourf(x1, x2, data[::-1])
plt.xlim(right=7000)
Related Posts Related Posts :
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • Python making a counter
  • Python rstrip and split
  • What does the String mean in numpy.r_?
  • How to correctly extend variable __all__ in a __init__.py?
  • Python behaves weird with piped input
  • Python 3 two dimensional list comprehension
  • How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in pyt
  • (Python Beginner) Need a start on classes
  • IndexError: At least one sheet must be visible
  • How to solve a system of linear equations over the nonnegative integers?
  • Pandas keep the most complete rows
  • "List index out of range" error in Python Memory Match game
  • Numpy: how to use argmax results to get the actual max?
  • Google Cloud Dataflow can't import 'google.cloud.datastore'
  • Calculate pandas DataFrame column by custom routine which accepts dictionary as input
  • Connect to a Class Method by it's method name holded into a var in a for loop in python
  • PyQt5 signals and threading.Timer
  • Replace 2 characters in a string in python
  • Passing command line arguments from a folder script to a file script
  • Understand the syntaxe X[Y == c] in Numpy
  • Optimize beginner python script about substring replacement
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org