# Help adding geometry to 2D contour plot

8 messages
Open this post in threaded view
|

## Help adding geometry to 2D contour plot

 I am currently using the script isolineslice.m to plot a 2D contour: isolineslice.mI would like to add the geometry to the 2D plot such as the one below: I have tried using "plotgeom" just before (**) and after (***) the "postplot" command:  % plotgeom (PROB, 'parent', f2) % ** % If want to display iso colors also: % postplot( fea2, 'parent', f2, 'surfexpr', 'u', 'isoexpr', 'u' ); postplot( fea2, 'parent', f2, 'isoexpr', 'u', 'isomap', cmap, 'isolev',... lvls, 'title', 'Slice ISO Lines', 'xlabel', 'x', 'ylabel', 'y', 'zlabel', 'z' ); % plotgeom (PROB, 'parent', f2) % *** ... but these calls seem to interfere with each other. I wondered about using "geom/plotgeom2" or "geom/plotgeomb" but they did not seem to be on the path.  Before I added "geom/" to the path I though I would just ask for help...... so Help, Randal
Open this post in threaded view
|

## Re: Help adding geometry to 2D contour plot

 Administrator This post was updated on . randress wrote I would like to add the geometry to the 2D plot such as the one below. ... I have tried using "plotgeom" just before (**) and after (***) the "postplot" command. I think it should work with plotgeom, but using postplot might be better to just visualize the geometry edges. I have tried the function call  postplot( PROB, 'boundary', 'on', 'surfexpr', 0, 'facecolor', 'none', 'colorbar', 'off', 'axis', 'off' ); postplot( fea2, 'parent', f2, 'isoexpr', 'u', 'isomap', cmap, 'isolev',... lvls, 'title', 'Slice ISO Lines', 'xlabel', 'x', 'ylabel', 'y', 'zlabel', 'z' ); view(2) using one of your previously attached models "cylinders_between_cylinders_in_boxv1.fea" and the command  isolineslice( fea, "s_dc*sqrt(Vx^2+Vy^2+Vz^2)", "XY", 0.5, 40, "jet" ) with seems to work as intended. As a side note, although it probably has nothing to do with this issue, I would suggest to avoid using the Matlab string type defined by double quotation marks ("string_string") in favor of the old single quote char type ('char_string'). At least for any inputs to FEATool function calls (such as postplot) as the string type is not backwards compatible and hence may not be handled properly everywhere (by FEATool functions). This also means that you can not use the following form (my_str == "my_string") to test for string (in-)equality, but must use either strcmp(my_str,'my_string') or isequal(my_str,'my_string') (as == with chars returns a logical array with one entry for every character). I have introduced functionality to try to catch and convert input strings to chars but this may not catch all possible cases.
Open this post in threaded view
|

## Re: Help adding geometry to 2D contour plot

 Precise Simulation wrote I think it should work with plotgeom, but using postplot might be better to just visualize the geometry edges. I have tried the function call  postplot( PROB, 'boundary', 'on', 'surfexpr', 0, 'facecolor', 'none', 'colorbar', 'off', 'axis', 'off' ); postplot( fea2, 'parent', f2, 'isoexpr', 'u', 'isomap', cmap, 'isolev',... lvls, 'title', 'Slice ISO Lines', 'xlabel', 'x', 'ylabel', 'y', 'zlabel', 'z' ); view(2)  I am sure the geometry outline will be just what I was looking for.  Thanks! Precise Simulation wrote As a side note, although it probably has nothing to do with this issue, I would suggest to avoid using the Matlab string type defined by double quotation marks ("string_string") in favor of the old single quote char type ('char_string'). At least for any inputs to FEATool function calls (such as postplot) as the string type is not backwards compatible and hence may not be handled properly everywhere (by FEATool functions). This also means that you can not use the following form (my_str == "my_string") to test for string (in-)equality, but must use either strcmp(my_str,'my_string') or isequal(my_str,'my_string') (as == with chars returns a logical array with one entry for every character). I have introduced functionality to try to catch and convert input strings to chars but this may not catch all possible cases. I do appreciate your pointing this out. IIRC, as I was tinkering with this script I began using single quotes (since that is how I saw that parameter passing implemented elsewhere), but I was having "is(not)equal" trouble (did not think of using c-like function calls...)  Any and all such corrections, comments, and suggestions, including those related to style, are greatly appreciated. Kind regards, Randal
Open this post in threaded view
|

## Re: Help adding geometry to 2D contour plot

 When I attempted to add the suggested modification to isolineslice.m here is what I came up with: isolineslice2.mand when I ran it against the result in the fea file in your reply "cylinders_between_cylinders_in_boxv1.fea" using he command: >> isolineslice2 ( fea, "s_dc*sqrt(Vx^2+Vy^2+Vz^2)", "XY", 0.5, 40, "jet" ) here is the 2D plot I got: isolineslice2_2D_plot.pngWhere did I go wrong ? -Randal
Open this post in threaded view
|

## Re: Help adding geometry to 2D contour plot

 Administrator When the FEATool GUI is active the plotting commands (postplot, plotgeom, plotgrid ...) will by default use the GUI figure/axes to plot in if no parent handle has been specified, so use the form:  postplot( prob, 'parent', f, ... ) like in the other plot commands in your isolineslice function, to specify a specific figure/axes to plot in.
Open this post in threaded view
|

## Re: Help adding geometry to 2D contour plot

 Ok. Got it. Here is the latest script with string types and comparisons corrected to be simple strings, the addition of a parameter to add value coloring along with the 2D contours, 2D geometry boundary displayed, more helpful titles, and a less cluttered colormap/key. isolineslice.mHere is an example of each plot type (3D, 2D, 2Dw/color): >> isolineslice( fea, 's_dc*sqrt(Vx^2+Vy^2+Vz^2)', 'XY', 0.5, 20, 'jet', 0) >> isolineslice( fea, 's_dc*sqrt(Vx^2+Vy^2+Vz^2)', 'XY', 0.5, 20, 'jet', 1) Couple more ideas for this script: Q1: Is there a call I could make from the script that would save the fea structure from FEATool (same as if I went to FEATool and did File-->Export FEA struct to MATLAB)? Q2: When I hover over an iso contour near a data point, it displays the coordinates.  How can I get it to display, in addition (or in its place), the value of the data at that point? (see below) Thanks again, Randal
 Administrator randress wrote Q1: Is there a call I could make from the script that would save the fea structure from FEATool (same as if I went to FEATool and did File-->Export FEA struct to MATLAB)? This should probably work:  h_menu_item = findall( 0, 'Label', 'Export FEA Struct To MATLAB' ); cbf = get( h_menu_item, 'Callback' ); cbf{1}( h, [], cbf{2:end} ); I will probably sooner or later add a custom slice functionality if you get tired of working on this. randress wrote Q2: When I hover over an iso contour near a data point, it displays the coordinates.  How can I get it to display, in addition (or in its place), the value of the data at that point? (see below) You have to create a custom datatip function, for example place/run this code after your plots:  fcn_datatip = @(~,info) num2str( get(info.Target,'UserData') ); h_figure = f2; % gcf() set( datacursormode(h_figure), 'UpdateFcn', fcn_datatip ); 
 Precise Simulation wrote This should probably work:  h_menu_item = findall( 0, 'Label', 'Export FEA Struct To MATLAB' ); cbf = get( h_menu_item, 'Callback' ); cbf{1}( h, [], cbf{2:end} );  Indeed it does! (h==>h_menu_item) I added a flag to the argument list to force export.  I still want to be able to plot from an fea struct that has been, perhaps, saved/archived a the MATLAB database. Precise Simulation wrote I will probably sooner or later add a custom slice functionality if you get tired of working on this. ... more likely you will grow weary of helping me "tweak" it :-) Precise Simulation wrote You have to create a custom datatip function, for example place/run this code after your plots:  fcn_datatip = @(~,info) num2str( get(info.Target,'UserData') ); h_figure = f2; % gcf() set( datacursormode(h_figure), 'UpdateFcn', fcn_datatip );  Again your suggestion did the job; I substituted sprintf to format the anon function return string and added the coordinates. nprec = 4; % add calling argument? fcn_datatip = @(~,info) sprintf ("%.3e at\n%s %s\n%s %s", ... get(info.Target,'UserData'), ... xlabel_2D, num2str( info.Position(1), nprec), ... ylabel_2D, num2str( info.Position(2), nprec)); h_figure = f2; % gcf() set( datacursormode(h_figure), 'UpdateFcn', fcn_datatip); Here is the current version: isolineslice.mAnd here's a call: >> isolineslice(fea, 1, 's_dc*sqrt(Vx^2+Vy^2+Vz^2)', 'XZ', 0.5, 20, 'jet', 2, 0) Here is what a 2D figure looks like: But you can see a bug/anomaly. Notice that the view of the geometry is that perpendicular to the XY plane (from out the z-axis) while the data view is indeed from the specified 'XZ' plane.   Here's the 3D view which looks correct: Is the geom going to have to be rotated with the view? How? or is there another way? Kind regards, -Randal