I am following this tutorial for manim: https://talkingphysics.wordpress.com/2019/01/08/getting-started-animating-with-manim-and-python-3-7/. Under heading 7.0: Graphing functions, the example shows code for plotting sine and cosine functions.
I was wondering if I could also fill the area covered between, let's say, sine function and the x-axis from x_min to x_max. I realized that the used PlotFunctions class has following hierarchy: PlotFunctions -> GraphScene -> Scene -> Container -> object (where -> denotes child of). But in this entire chain of hierarchy, I do not see a config option such as fill_color that is present in VMobject.
I'm also not readily able to locate any code that helps in doing so, although I'm sure that some really easy 1 line code must exist since this is used in so many 3blue1brown videos. I would really appreciate some help with this!
You can check this github issue, it might be something your'e looking for.
It hasn't been merged onto the main branch so this could be a work-around for now.
After looking more into the code, I still don't see a 1-liner code per se but did find that to color the area under the graph, a set of riemann rectangles of very small width (~0.01) are used. This makes the graph look colored.
I used get_point_from_function() option to get the points and passed them to create a Polygon filled with colour.
you can check it here , look at def get_region()
Related
I am working in my graduation project and one of the tasks I am required to draw a 3D shape(for example an ellipsoid using vtkSampleFunction), this represents the heart for example. I need to change the color of certain areas in that shape and make color gradients using 2 colors for example. How can this be achieved? All I could find is that cant be done without having polydata(points) and I dont know how to access specific points on the outline of my shape. Any help would be appreciated
I tried millions of ways to access points on the outline of my shape but I cant find anyway to do it.
I am new to VTK so please try to simply any answer. Thank You
If you are looking for a way to extract all the points inside a surface, you can use the vtkSelectEnclosedPoints method. For example, if you want to find out which all points in pointsPolydata lie inside the surface surfacePolydata, you can use the below example.
select = vtkSelectEnclosedPoints()
select.CheckSurfaceOn ()
select.SetTolerance(0.001)
select.SetInputData(pointsPolydata)
select.SetSurfaceData(surfacePolydata)
select.Update()
outPut=select.GetOutput()
The outPut polydata will have an array named "SelectedPoints", with 0 for point outside the surface and 1 for points inside the surface.
For more details, refer vtkSelectEnclosedPoints
My goal is to change the aspect of the graph produced using the shap.summary_plot in Python.
For instance, taking the example from here
I would like to change the horizontal label from "SHAP value (impact on model output)" to a different text, and I would like to move the vertical bar "Feature Value" horizontally below the graph.
The source code of the function is here, but I have been struggling in understand how to get my goals. Any comment or suggestion is highly welcomed.
UPDATE:
A recent like on this question - thanks! - reminded me that I indeed managed to find a way, which I'll share on GitHub soon.
i want to create a plot with 13 different arrow styles for a vector field showing the stream of a sea. I want to use very specific arrows which are not bult in FancyArrowPatch. Is ther a possibility to use a selfmade design as arrow in python ? Is it possible to somehow add custom arrow styles to the FancyArrowPatch function ?
I have attached the image I want to reproduce with Python (taken from bsh.de/DE/DATEN/Stroemungen/stroemungen_node.html):
My best try was to produce this one:
Which is not quite satisfying yet. I would like to have the same arrows as seen in the first image. If you have suggestions how to make the image fancier I am open for that too.
I am trying to model spherical aberrations as a function of the tilt angle of a mirror in an optical system. I am using Optics Studio for the model and PyZDDE to communicate with it. I thought this would be easy; I would setup a list of tilt angles and then loop over them changing the relevant surface parameters and calling zGetZernike():
for i in range(len(angle)):
ln.zSetSurfaceParameter(n, 54, angle[i])
ln.zSetSurfaceParameter(n, 64, -angle[i])
ln.zGetZernike()
print(Zern[1])
However, this didn't work.
I am getting the same Zernike coefficients independent of angle. I tried calling ln.zPushLens(1) and ln.zGetUpdate() but neither one worked. It looks like the changes are not getting updated on the server side.
I also tried introducing coordinate breaks before and after the mirror surface and changing the angles for those surfaces but that didn't work either.
What am I missing and what can be done to make this work ?
I would also like to change the wavelength, but that doesn't seem to work either. I call ln.zSetPrimaryWave(N), where N is a wave number, but the server always uses the first wavelength from the settings in Optics Studio.
Is there a way to change the wavelength with which the Zernike coefficients are calculated ?
Please use the parameter numbers 3 and 4 (instead of 54 and 64) with the function zSetSurfaceParameter().
The codes SDAT_TILT_X_BEFORE (54) and SDAT_TILT_X_AFTER (64) respectively are meant to be used with the function zSetSurfaceData(), which sets the appropriate fields in the Surface Properties >> Tilt/Decenter Tab for the specified surface in the main Zemax/OpticStudio application.
Please note that you need to use parameters 3 and 4 (with the function zSetSurfaceParameter()) if you are using coordinate breaks. Additionally, you may use parameter numbers 1 and 2 if the surface type is tilted.
I'm not sure why the function zSetPrimaryWave()is not working for you. I just tested the function in OpticStudio, and it works as expected.
Regards,
Indranil.
As it turned out changing tilts and decenters directly from surface properties using zSetSurfaceParameter() didn’t work. I had to use two coordinate breaks, one in front of the mirror surface and one behind it, and to set the tilts and decenters for those surfaces using zSetSurfaceParameter(). I chose to set a pickup solve on the second surface that restores the geometry behind the mirror and was only changing the tilts and decenters on the first surface. The parameter numbers for x tilts and y tilts are 3 and 4 correspondingly, as described in the Optics Studio manual. For debugging it really helps to push the lens to the lens editor after each change of parameters (zPushLens(1)). One should also consider saving intermediate configurations as Zemax design files. However for the actual calculation none of this is necessary. Also Optics Studio uses the first wavelength in the settings for the Zernike calculation. I had to change the wavelength using zSetWave(). Thanks to Indranil and ZEMAX technical support for valuable advice and guidance along the way.
I am developing a wxpython project where I am drawing a diagram on to a panel that I need to be able to zoom in/out to this diagram(a directed acyclic graph in my case). I will achieve this by mouse scroll when the cursor is on the panel, however that is not a part of my question. I need an advice from an experienced person about the method I am using for zooming. So far I thought as doing,
There are lines, rectangles and texts inside rectangles within this diagram. So maybe I could increase/decrease their length/size with the chosen mouse event. But it is hard to keep it balanced because rectangles are connected with lines their angles should not change, and texts inside the rectanges should stay in the middle of them.
Other method I thought of doing is to search for a built-in zoom method. Which I heard about something like Scale. However I have some questions about this method. Will this work on vector drawings(like mine) rather than images. And will it be scaling only the panel I chose and not the whole screen ? After I hear your advice about this, I will look deeper into this, but now I am a bit clueless.
Sorry if my question is too theoretical. But I felt I needed help in the area. Thanks in advance.
Note: Zooming not necessarily applied by scrolling.
Note2: My research also led me to FloatCanvas. Is this suitable to my needs ?
Yes, from your description FloatCanvas would certainly meet your needs.
Another possibility to consider would be the wx.GraphicsContext and related classes. It is vector-based (instead of raster) and supports the use of a transformation matrix which would make zooming, rotating, etc. very easy. However, the actual drawing and management of the shapes and such would probably require more work for you than using FloatCanvas.