I solved it with these commands to label the end points of the log axis - real y= point(S).y; string Xmin = "$"+format("%.0e",true,xmin)+"$"; string Xmax = "$"+format("%.0e",true,xmax)+"$"; xtick(spk_data,shift(0,-5pt)*Label(Xmin),(xmin,y)); xtick(spk_data,shift(0,-5pt)*Label(Xmax),(xmax,y)); I am plotting a semi-log plot. The xaxis goes from 20 to 20000. I am using the following code for plotting: void plot() { picture spk_data; size(spk_data,800,400,IgnoreAspect); scale(spk_data,Log,Linear); xlimits(spk_data,20.0,20000.0);...
I figured it out, the correct call is secondaryY(plt_data, etc. then it works. If I use the default pic and then plot secondary axis (as in the example in the 2d graphs) everything works fine. If I name the graph say with picture plot_data; and execute all commands with a picture argument set to plt_data and do not try to add the secondary axis every works fine but if I then try to execute the secondary axis code I get the error - if(!primary.scale.set) abort(noprimary); ^ /usr/local/share/asymptote/graph.asy:...
If I use the default pic and then plot secondary axis (as in the example in the 2d graphs) everything works fine. If I name the graph say with picture plot_data; and execute all commands with a picture argument set to plt_data and do not try to add the secondary axis every works fine but if I then try to execute the secondary axis code I get the error - if(!primary.scale.set) abort(noprimary); ^ /usr/local/share/asymptote/graph.asy: 1823.31: Primary axis must be drawn before secondary axis Here is...
I am plotting a semi-log plot. The xaxis goes from 20 to 20000. I am using the following code for plotting: void plot() { picture spk_data; size(spk_data,800,400,IgnoreAspect); scale(spk_data,Log,Linear); xlimits(spk_data,20.0,20000.0); ylimits(spk_data,0,100); draw(spk_data,graph(spk_data,col_data[0].data,col_data[1].data),black); yaxis(spk_data,latex_names[1], LeftRight(), RightTicks(pTick=.8red, ptick=grey, extend=true)); xaxis(spk_data,latex_names[0], BottomTop(), Ticks(Label("$%.2f$",black),beginlabel=true,...
Thank you again for a really great piece of software. I proselytize it every chance I get. On 3/28/24 11:48 AM, John Bowman wrote: You forgot the picture argument to graph (which defaults to currentpicture). Just change your draw commands to read: |draw(pic,graph(pic,W_dB,flow,fhi,npts),black,"Woofer"); draw(pic,graph(pic,LM_dB,flow,fhi,npts),red,"Lower Mid Range"); draw(pic,graph(pic,UM_dB,flow,fhi,npts),green,"Upper Mid Range"); draw(pic,graph(pic,T_dB,flow,fhi,npts),blue,"Tweeter"); draw(pic,graph(pic,IN_dB,flow,fhi,npts),cyan,"System...
My bad. I only included code fragments of the critical lines. In what is not shown I import both graph and math (what is not shown is calculating the curves but does not use any graphical commands). I have attached the complete code for both cases. Note that in the case that does not work if I comment out the xaxis command I do not get an error but of course the xaxis shown is linear and not log. On 3/27/24 7:34 PM, John Bowman wrote: Among other errors, you need to |import graph;| The next error...
When I run the following code (complete program attached) -_ picture pic; size(pic,800,400,IgnoreAspect); scale(pic,Log,Linear); real flow = 1.0; real fhi = 20000.0; int npts = 1000; draw(pic,graph(W_dB,flow,fhi,npts),black,"Woofer"); draw(pic,graph(LM_dB,flow,fhi,npts),red,"Lower Mid Range"); draw(pic,graph(UM_dB,flow,fhi,npts),green,"Upper Mid Range"); draw(pic,graph(T_dB,flow,fhi,npts),blue,"Tweeter"); ylimits(pic,-40,25); yequals(pic,0); xlimits(pic,1.0,15000.0); yaxis(pic,"$\left | H_{dB}(f)...
I have a table I wish to interpolate as part of an intermediate calculation of a function I want to draw. The documentation is not clear on whether this can be done or not. It refers to an example Interpolate1.asy which I can't find. Can anyone help me out on this problem.
I have used Asymptote quite a bit and am now learning the Julia programming language. I feel that Julia is very similar to Asymptote programming especially in that both use multiple dispatch in defining functions. I would like to hear what any of you more familiar with Julia than I am think of this.
I am trying to extend my ticks as in the example loggrid.asy. Using my attached code and not extending the ticks my output is shown in CBT36K_Filters-1.eps. If I uncomment the the code for the xaxis and yaxis for extending the ticks (and commenting the old xaxis and yaxis) the resulting output is shown in CBT36K_Filters-2.eps with the error message - yaxis("$y$",LeftRight,RightTicks(begin=false,end=false,extend=true,ptick=thin)); ^ ./CBT36K_Filters.asy: 141.13: use of variable 'LeftRight' is ambiguous...
I am trying to apply the shift transformation to a label (a png image). Rotate and scale work when applied to the image but shift does nothing. I have attached code that demonstrates this problem along with the image I am using. I am looking for a solution that treats paths and labels (images) in the same manner. Any help would be appreciated.
I am trying to apply the shift transformation to a label (a png image). Rotate and scale work when applied to the image but shift does nothing. I have attached code that demonstrates this problem along with the image I am using. I am looking for a solution that treats paths and labels (images) in the same manner. Any help would be appreciated.
Aside from the graphics structures and functions is there a listing of the differences between Asymptote code and C code other than the graphics calls. Three I have found is that - C-code: real a[4] = {1,2,3,4}; Asymptote-code: real[] a={1,2,3,4}; C-code: complex z; Asymptote-code: pair z; In addition Asymptote can slice arrays and has built in data types such a "triple." The reason for my question is that sympy/python has a code generator for C-code that with some minor modifications should be able...
Is this the sort of thing you were thinking about (It was done using Sphinx) - https://galgebra.readthedocs.io/en/latest/ I wrote the original code but was not comfortable using Sphinx (All the documentation I wrote was in LaTeX) so the code was taken over by geometric algebra enthusiasts at Cambridge University and they are the ones the wrote the online documentation (in addition to improving the code). On 3/8/23 1:31 PM, Jamie wrote: For contribution guidelines, we do not have yet a contribution...
Is there a write up on how to contribute to Asymptote (asy code) and how contributions should be documented outside of commenting the code (multi line comments would help here). Did you ever consider using Sphinx to document the Asymptote software package or applying to the Google summer of docs - https://opensource.googleblog.com/2022/02/Announcing%20Season%20of%20Docs%202022.html
Here is a simple code example - import graph; size(20cm,10cm,IgnoreAspect); xaxis("$X$",xmin=10,xmax=20,Ticks); yaxis("$Y$",ymin=0,ymax=100,Left,Ticks); pair p1 = (12.5,20); pair p2 = (17.5,75); draw(p1--p2); real len = 1cm; real ext = 1cm; arrow(Label("dim"),p1,W,len,E,margin=NoMargin); arrow((p2.x,p1.y),E,len,W,margin=NoMargin); arrow(p1,S,len,N,margin=NoMargin); arrow(Label("dim"),(p1.x,p2.y),N,len,S,margin=NoMargin); with attached output. All I want to do is shift the two horizontal arrows a...
I am drawing lines on my plot. I wish to draw the line from pair p (graph coordinates) to p+dp where dp.x and dp.y are specifed in say cm and not graph coordinates. For example I am plotting exterior dimension and extension lines for horizontal and vertical dimensions and I want to set the length of the lines to be say a value in cm and not depend on the graph coordinates. I saw the Scale function which goes from graph to user coordinates. Is that what I should use to determine the length of my lines...
I am trying to annotate my plot with dimensions (arrow pairs with labels) where I am also plotting a curve on a secondary axis. The problem shown in EV_Charge_1.pdf is that when an arrow that is part of the annotation is plotted outside of the secondary y-axis [ymin,ymax] the plot is messed up. If I do not plot the arrow outside the secondary [ymin,ymax] everything plots fine (EV_Charge.pdf). I have included the code fragment where I draw the the dimension annotations and the secondary axis curves....
I have paths filled with colors or patterns each of which means something different. I would like to have a legend that includes the colors of patterns and their meanings. In searching the forum I could not find an examples of this topic. Any help would be appreciated. Note that legend would also include line types from curves with the appropriate annotations for each curve as om a standard legend. I have attached a pdf file of the sort of plot I wish to attach legends to.
I got to work with this code but I don't know why it works or how to fine tune the position of the embedded graph - // Square Pulse with Fourier Transform PulseGate pulse; pulse.init(T); picture pic0,pic0a,pic0b,pic1,pic2,pic3,pic4,pic5; size(pic0a,250,175,IgnoreAspect); draw(pic0a,graph(pic1,ScaleShift(T,pulse.f),-1,1,1000)); xaxis(pic0a,"$t/T$",Bottom,Ticks); yaxis(pic0a,"$\f{f}{t}$",Left,Ticks,ymin=0.0,ymax=1.2); size(pic0b,600,400,IgnoreAspect); draw(pic0b,graph(pic0b,ScaleShift(pulse.Fabs,T),-10,10,1000));...
I have looked at the post on embedding graph and cannot understand it to help me in my problem. I wish to draw one graph inside another graph. My particular problem is I have graph of the Fourier Transform of a time function and the graph of the function of time. I want the plot the function of time inside the axes (upper right hand corner with reduced size) of the Fourier Transform graph to show in one picture the relation between the two functions. There must be a way to do this but it must use...
I have looked at secondaryX and secondaryY but want I wish to do is have secondary axes on both X and Y. I wish to plot one function with respect to an x bottom and y left axes and another function with respect to x top and y right axes since each function can have very different x and y domains. Is there a way to do this with Asymptote. Note that I have been able to plot functions with a common X and a secondaryY axis using your demo code as a template.
I figured it out - `typedef real REALFCT(real x); typedef pair CMPLXFCT(real x); CMPLXFCT operator(CMPLXFCT f1,CMPLXFCT f2) { return new pair(real x) {return f1(x)f2(x);}; } REALFCT operator(REALFCT f1,REALFCT f2) { return new real(real x) {return f1(x)f2(x);}; }`
I have two functions: pair f1(real x); pair f2(real x); and I want to overload * so that if pair f(real x) = f1*f2; f(x) returns f1(x)*f2(x) I think it is simple but I cannot find any examples in the forum with my searches. I think my problem is that the overloaded operator has to return a new function and I have forgotten how to do that.
First, Asymptote is better than anything else around for technical graphics. I use python to write some parts of Asymptote code when I am want to use symbolic math expressions generated in python (sympy) to numerical functions in Asymptote. For one line symbolic expressions this is no problem (polynomials, combined with exp(x), sin(x), etc). However if the symbolic functions need "for" loops or "if" statements in their definition things (piecewise functions for example) get much more complicated....
I saw a conversation about this on this site dating from 2011. Has anything more been done about it. I am not concerned about the drawing commands but rather converting a function to be plotted from C to Asymptote code. Note what I am actually trying to do is use Asymptote to plot from the symbolic algebra package sympy written in python. However, sympy has a code generator to convert sympy python to C/C++. I would convert a symbolic function to a real function (one or two variables possibly a parametric...
If I run "asy -f pdf cv2.asy" in Ubuntu it just creates the pdf file. If I run it in the terminal or as a process in python in Win 10 it also opens the pdf file in a viewer. I don't want to do this. I am converting the pdf file to a png file so I can insert it in a Jupyter notebook. Any suggestions?
As always thanks again.
How to I find the limits of an existing graph (one that has been draw) so that I can make sure additional line segments that I would draw on the graph do not exceed the limits?
Thank you for your efforts. What I am doing is defining a piecewise function where on each interval of a grid I define an arbitrary function. I was hoping that instead of having to define the function on each interval separately (note that functions are not restricted to polynomials where I could just use a coefficient array) that I could use an array of strings so for example using eval I could convert the string "xsin(2x)+exp(x)" to real f(real x) { return xsin(2x)+exp(x); } In my case this is...
When I run the following function - REALFCT[] fctarray(string[] s) { REALFCT[] F; REALFCT fofx; for (int i = 0; i < s.length; ++i) { string S = "real f(real x){ return "+s[i]+";}"; write(S); eval(S,true); fofx.f = f; F.push(fofx); } return(F); } I get the error that f does not exist for "fof.f = f" for the string S = "real f(real x){ return 1+x;}" Am I using eval incorrectly or is what I want to do impossible?
If am trying to create a class (struct plus functions) for a piecewise function. To do this I need a structure that has as one of it's elements an array of functions. My question is how do I declare such a thing and how do I initialize it. In my case the functions are just polynomials defined on different intervals so also for initialization is there a way of converting a text string to Asymptote code so I could have an argument of an initialization function say "x**2+2*x+3" and the initialization...
If am trying to create a class (struct plus functions) for a piecewise function. To do this I need a structure that has as one of it's elements an array of functions. My question is how do I declare such a thing and how do I initialize it. In my case the functions are just polynomials defined on different intervals so also for initialization is there a way of converting a text string to Asymptote code so I could have an argument of an initialization function say "x*2-2x+3" and the initialization...
If am trying to create a class (struct plus functions) for a piecewise function. To do this I need a structure that has as one of it's elements an array of functions. My question is how do I declare such a thing and how do I initialize it. In my case the functions are just polynomials defined on different intervals so also for initialization is there a way of converting a text string to Asymptote code so I could have an argument of an initialization function say "x**2-2x+3" and the initialization...
Thank you again for a great code package. Did you ever consider having some students apply to the Google Summer of Code to either write a python wrapper for Asymptote or expand the current documentation. More examples and maybe a Sphinx online version similar to this - https://galgebra.readthedocs.io/en/latest/ I do try to proselytize Asymptote whenever I can (I got some people in Germany to use it and give a talk about it) and being retired I had time to learn a new language but I think a python...
The problem with the output is that except for the ticks at -f0 and f0 the data obscures the tick marks. I am looking for a way to put both the tick marks and the tic labels beneath the x-axis.
I have attached the entire program which will run but the critical part is - xaxis(PIC,"$f$",NoTicks); real y=point(S).y; xtick(PIC,scale(xscale)*Label("$f_0$"),(X.f0,y),dir=N); xtick(PIC,scale(xscale)*Label("$-f_0$"),(-X.f0,y),dir=N); if ( Ntics > 1 ) { real Df_tic = df/Ntics; int im1; for (int i = 2; i <= Ntics; ++i) { im1 = i-1; real x_pp = 1.0+im1*Df_tic; real x_pm = 1.0-im1*Df_tic; real x_mp = im1*Df_tic-1.0; real x_mm = -im1*Df_tic-1.0; xtick(PIC,scale(xscale)*Label("$"+(string) x_pp+"f_0$"),(x_pp*X.f0,y),dir=N);...
I am making custom xticks. I want the tick and the tick label to be on the same side of the axis since in my plot. Having them on opposite sides of the axis obscure the tick marks due to the form of the data being plotted. I have searched the forum and cannot find an example of this situation. I have attached the plot so you can see what the problem is.
Thank you. On 3/29/22 5:57 PM, John Bowman wrote: Here's a simple example: |import graph; size(10cm); struct A { int n=3; real f(real x) { return x^n; } } A a; draw(graph(a.f,-1,1),red); | Injecting parameters for construction of a curve or surface https://sourceforge.net/p/asymptote/discussion/409349/thread/33a828c707/?limit=25#5362 Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/asymptote/discussion/409349/ To unsubscribe from further messages, please visit...
Do you mean a class with an anonymous function as one of the members or something else?
Many of the plotting functions require a function of a pair or a triple that returns a pair or a triple. These functions in practice could also depend on several parameters. I am trying to determine the best way to create such a function without hard coding the parameters into the function. In C++ or Python I could use classes. The two ways I have found in Asymptote is to make the parameters global (define the values outside the function which is ugly) or to write a function that I input the parameters...
Dumb me. Of course a parametric surface. Thank you. On 3/29/22 1:38 PM, John Bowman wrote: As mentioned in the documentation, you can use one of these functions to draw a parametric surface (say with u=r and v=theta): |surface surface(triple f(pair z), real[] u, real[] v, splinetype[] usplinetype, splinetype[] vsplinetype=Spline, bool cond(pair z)=null); surface surface(triple f(pair z), pair a, pair b, int nu=nmesh, int nv=nu, bool cond(pair z)=null); surface surface(triple f(pair z), pair a, pair...
I have a surface that I can efficiently calculate (within Asymptote) as a function of r and theta. It is inefficient (slow) to calculate it as a function of x and y (it involves the Bessel functions K and I). In the documentation I could not find a way to plot it directly on the polar grid I calculate it on. Am I missing a capability of Asymptote plotting functions or is there another way of using the data I generate on the polar grid? Thanks in advance for any help you can offer.
VectorField.asy is a Asymptote library to allow simple plotting of vector fields on arbitrary point arrays. void vectorfield2d(pair [] xy,pair f(pair z),real scale=0,pen pen=solid,arrowbar arrow = Arrow) Plots the 2d vectorfield on the array of points "pair [] xy" defined by the vector function "pair f(pair z)" with example "2WireCable2d.asy" void vectorfield3d(triple [] xyz,triple f(triple xyz),real scale=0.0,pen pen=solid,arrowbar3 arrow = Arrow3) Plots the 3d vectorfield on the array of points...
Disregard previous post. I found arrowbar3!
As you suggested I am coding some examples. I want to generalize my code to 3d but getting an error from the statement - void vectorfield3d(triple [] xyz,triple f(triple xyz),real scale=0.0, arrowbar arrow = Arrow3) The error is - VectorField.asy: 51.88: cannot cast expression to 'bool(picture, path, pen, marginT(path, pen))' I think I am using the wrong data type for Arrow3 but I can't find the datatype for Arrow3 in the documentation. Is that my problem?
As you suggested I am coding some examples. I want to generalize my code to 3d but getting an error from the statement - void vectorfield3d(triple [] xyz,triple f(triple xyz),real scale=0.0, arrowbar arrow = Arrow3) The error is - VectorField.asy: 51.88: cannot cast expression to 'bool(picture, path, pen, marginT(path, pen))' I think I am using the wrong data type for Arrow3 but I can't find the datatype for Arrow3 in the documentation. Is that my problem?
The special functions I can access in the gsl library are very useful to me. I would request wrappers for more of the gsl library to do the heavy numerical lifting in generating plots. Especially useful to me and I would hope others would be to access the differential equation solvers in gsl from Asymptote. I am proselytizing Asymptote every chance I get. I keep hoping that additional Asymptote would be included in the Google summer of code.
I wrote routines to do what I wanted after looking at the arguments to "vectorfield." The routines are attached
I am plotting the magnetic field produced by a three phase power cable. I found this in the Asymptote examples - **import graph; size(100); pair a=(0,0); pair b=(2pi,2pi); path vector(pair z) {return (0,0)--(sin(z.x),cos(z.y));} add(vectorfield(vector,a,b));** and the forum entry on how to apply it to 3 dimensions. My question is can this method be used to plot the field over a predefined point set rather than the automatically generated rectangular grid defined by a and b in the example. For example...
The definition of fft is - pair [][] fft(pair [][] a) Two questions - 1. Is pair used because the output will be complex so you must the define the input for a real function as (f(x),0.0)? 2. Why isn't the input just pair [] a instead of pair [][] a? I could not find a detailed description of the fft input and output anywhere in the documentation.
First, thank you for the simplified code, great software, and maintaining the software. I proselytize Asymptote every chance I get. I would also like to proselytize something else to that might be of interest to you, Geometric Algebra. The most relevant reference would be the book "Geometric Algebra for Computer Science" - https://geometricalgebra.org/ http://geometry.mrao.cam.ac.uk/2005/01/applications-of-conformal-geometric-algebra-in-computer-vision-and-graphics/ One of the strong points of geometric...
The problem is in the phase (bottom) graph. On 2/5/22 6:41 PM, John Bowman wrote: Here's how to make |ymin=0| in the gain graph: ylimits(gain,0,1); xaxis(gain,"$\wB$",BottomTop,LeftTicks); yaxis(gain,"$\abs{\bfrac{\gfct{\wB}}{\gfct{1}}}$",LeftRight,RightTicks(trailingzero)); Labeling and positioning axes https://sourceforge.net/p/asymptote/discussion/409349/thread/d74025af41/?limit=25#1300 Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/asymptote/discussion/409349/...
I have not been able to label the y-axis tick at ymin. Also I have not been able to locate the x-axis at y=0. I have set the flags in xaxis and yaxis that should let me do this to no effect. I am soliciting any suggestions. Run attached file to see problem in lower graph. Also of interest should be my function to label axis using pi fractions useful for axis in radian units.
I have install a xonar essence stx ii 7.1 on my ubuntu 16.04 htpc. I was using the analog line in and the spdif (rca) output. Initally both worked. I did a standard ubuntu upgrade and neither worked. Reverting the kernel did not help. My system is dual boot with win 10. The sound card works on win 10. I tested the card (both when it worked and when it didn't) by playing music with kodi. I explicitly selected the stx spdif output device with the kodi system menu. I am looking for any suggestions to...
I running ubuntu 16.04 and wish to route the audio output of Kodi to ecasound for post processing. Kodi will not let me pipe audio. I can only send the Kodi audio to an alsa device. I have a sound card (Xonar D2) with an spdif output and input. I could connect a cable between the output and input with Kodi configured to send audio to the spdif ouput put and ecasound configure to read from the spdif input. My question is there a simple way using alsa to do the same thing in software. If this is possible...