Plotting Arrays
Date | 2016-07-19 18:31 |
From | Steven Yi |
Subject | Plotting Arrays |
Hi All, I've been looking at a bit of matlab code today and was thinking it would be nice to have a plot opcode in Csound that took in an array and plotted it. I suppose this email is speculation upon the topic and I'm interested to hear what others might think. I suppose the existing ftable plotting facilities could be used, but I think I'd prefer an explicit graphing call rather than an implicit one when ftables are created. Also, here are plenty of plotting systems in other languages and libraries and they are generally very extensive. Francois' article [1] from the Csound Journal shows use of the Python API to use matplotlib to plot ftables. Getting from arrays to ftables would still be necessary as well as running Csound from within Python. I suppose what I'm interested is something like: kyvals[] init 1024 kxvals[] init 1024 ... processing ... plot kyvals, kxvals ... processing ... plot kyvals, kxvals I don't know what is a good solution at this point. Anyone have thoughts on the subject? (If there's a workaround that doesn't require modifying Csound, that'd be particularly nice. :) ) steven [1] - http://csoundjournal.com/issue14/realtimeCsoundPython.html Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2016-07-19 18:34 |
From | Francois PINOT |
Subject | Re: Plotting Arrays |
Another solution is to use a Jupyter notebook with the new implementation of ICsound as a 2016-07-19 19:31 GMT+02:00 Steven Yi <stevenyi@gmail.com>: Hi All, |
Date | 2016-07-19 18:36 |
From | Francois PINOT |
Subject | Re: Plotting Arrays |
Another solution is to use a Jupyter notebook with the new implementation of ICsound as a magic command (See https://github.com/fggp/ctcsound/blob/master/cookbook/07-icsound.ipynb) Regards2016-07-19 19:31 GMT+02:00 Steven Yi <stevenyi@gmail.com>: Hi All, |
Date | 2016-07-19 18:51 |
From | Steven Yi |
Subject | Re: Plotting Arrays |
Hi Francois, Yes, this is similar to what was linked to in the CSJ article. Again the work is done outside of Csound and requires transferring the array to an ftable. This would work, but it's a bit inconvenient compared to having an opcode call within Csound code (at least, with the workflow I'm using of editing UDO code within Vim and wanting to visualize the results). I suppose I could just generate new ftables from the array data and depend upon Csound built-in ftable plotting for what I was working on for now. Setting up a Jupyter notebook may be something that could work if I could also #include files within a %%csound magic command. As it is now, I have my UDO code I'm working on, then a test.csd that #includes the file. If the notebook can #include, the notebook could take the place of the test.csd, which could be very interesting. Well, food for though! Thanks for mentioning this, I'll schedule some time to setup ctcsound and Jupyter here and experiment with it. steven On Tue, Jul 19, 2016 at 1:36 PM, Francois PINOT |
Date | 2016-07-19 19:06 |
From | Victor Lazzarini |
Subject | Re: Plotting Arrays |
you can also import pylab in one of the Python opcodes and do it all from there. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland > On 19 Jul 2016, at 18:51, Steven Yi |
Date | 2016-07-19 19:30 |
From | Steven Yi |
Subject | Re: Plotting Arrays |
I think this would be closer to what I was looking for. I haven't used the python opcodes in a long, long time. I just tried a simple csd with pyinit and get an error with "Import Error: no module named site", which makes me think that this is related to Oeyvind's post the other day. I'll have to investigate further once a solution for that is found. Jupyter notebook was easy to setup. Francois: For ctcsound, there is no installer for it at the moment. I copied this into my python2\Lib\site-packages. Are there plans to create an easy_install package or to distribute ctcsound so that it can be installed with pip? On Tue, Jul 19, 2016 at 2:06 PM, Victor Lazzarini |
Date | 2016-07-19 19:57 |
From | Victor Lazzarini |
Subject | Re: Plotting Arrays |
I found this code by Andreas Bergsland, runs well here on OSX /* Plot - Plots one or two(optional) values on a two axes plot DEPENDENCIES Requires the python modules matplotlib, numpy and drawnow DESCRIPTION Plot - Plots one or two(optional) values on a two axes plot with user defined range SYNTAX kdummyoutput Plot iupdaterate, imin1, imax1, kval1 [,iplot2, imin2, imax2, kval2] INITIALIZATION iupdaterate - the rate with which the plot is updated. Defaults to 20. imin1 - minimum for value 1 imin2 - maximum for value 1 iplot2 - set >= 0 to use second plot (optional) imin2 - minimum for value 2, defaults to 0 (optional) imax2 - maximum for value 2, defaults to 1 (optional) PERFORMANCE kval1 - first value to plot kval2 - second value to plot (optional) kout - dummy output (same as kval1) CREDITS Andreas Bergsland 2015 */ opcode Plot, k, iiikoopO iupdaterate, imin1, imax1, kval1, iplot2, imin2, imax2, kval2 xin pyinit pyassigni "min1", imin1 pyassigni "max1", imax1 pyassigni "min2", imin2 pyassigni "max2", imax2 pyassigni "plot2", iplot2 if iupdaterate <= 0 then iupdaterate = 20 endif pyruni {{ import numpy import matplotlib.pyplot as plt from drawnow import * data1=[] #make lists data2=[] cnt=0 plt.ion() #tell matplotlib to operate in interactive mode def PlotFigure(): plt.ylim(min1,max1) plt.grid(True) plt.plot(data1, 'ro-') if plot2 > 0: plt2=plt.twinx() plt.ylim(min2,max2) plt2.plot(data2,'b^-') }} pyassign "val1", kval1 pyassign "val2", kval2 ; Update frequency for plot ktrig metro iupdaterate ; Update sequence pyrunt ktrig, {{ data1.append(val1) data2.append(val2) drawnow(PlotFigure, 'ro-') cnt = cnt + 1 if (cnt>50): data1.pop(0) data2.pop(0) }} xout kval1 ; Dummy output endop ; Use example instr 1 kval1 lfo 1, 1.1, 0 kval2 lfo 5, 0.7, 1 kdum Plot 20, -1, 1, kval1, 1, -5, 5, kval2 endin =========== ======================== Dr Victor Lazzarini Dean of Arts, Celtic Studies and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 19 Jul 2016, at 19:30, Steven Yi |
Date | 2016-07-19 20:16 |
From | Ed Costello |
Subject | Re: Plotting Arrays |
I tried this. A good way of doing stativ / real-time plots is with websockets opcode sending whatever data to a browser, then use something like D3.js to do the plotting. Have a real-time spectrogram example i could dig up of anyone wants. On Tue, 19 Jul 2016 19:57 Victor Lazzarini, <Victor.Lazzarini@nuim.ie> wrote: I found this code by Andreas Bergsland, runs well here on OSX -- Edward Costello |
Date | 2016-07-19 20:29 |
From | Victor Lazzarini |
Subject | Re: Plotting Arrays |
yes, it's not a problem using an environment outside Csound like python with pylab, but that is not what steven was asking. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
Date | 2016-07-19 21:42 |
From | Ed Costello |
Subject | Re: Plotting Arrays |
Ah yeah, sorry about that, although, being able to instantiate a web view to do things like plotting within Csound would be pretty nice, pythons plotting facilities are great, I have a feeling though that using a web view with things like D3 would be also be fantastic, not to mention being able to load up widgets in there as well. Supercollider seems to have one. Ed On Tue, 19 Jul 2016 at 20:30 Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
-- Edward Costello |
Date | 2016-07-19 22:21 |
From | Richard |
Subject | Re: Plotting Arrays |
Good idea, I would recommend C3.js, makes it easier to use D3... Richard On 19/07/16 22:42, Ed Costello wrote:
|
Date | 2016-07-19 22:37 |
From | Richard |
Subject | Re: Plotting Arrays |
That would be interesting Ed. Could you post this? Richard On 19/07/16 21:16, Ed Costello wrote:
|
Date | 2016-07-19 22:46 |
From | Anders Genell |
Subject | Re: Plotting Arrays |
I would LOVE a plot opcode! Would it be possible to apply gnuplot in some manner, like GNU Octave does? Regards, Anders > 19 juli 2016 kl. 20:30 skrev Steven Yi |
Date | 2016-07-19 23:24 |
From | Ed Costello |
Subject | Re: Plotting Arrays |
Attachments | Website.zip |
If anyone is interested, attached is a zip that contains a website and a csd file. This needs the websocket opcode, start a web server in the website directory, start the main.csd file and then go to the website, you should see an animated spectrogram. It uses D3 for the axis and just a plain canvas for the spectrum. Cheers Ed On Tue, 19 Jul 2016 at 22:47 Anders Genell <anders.genell@gmail.com> wrote: I would LOVE a plot opcode! -- Edward Costello |
Date | 2016-07-21 15:16 |
From | jpff |
Subject | Re: Plotting Arrays |
My instinct would be to write an opcode that writes arrays to a tmp file and then evoked gnuplot. ot ard to do but is it sufficiently generic? At least it should work from all csound frontends. On Tue, 19 Jul 2016, Steven Yi wrote: > Hi Francois, > > Yes, this is similar to what was linked to in the CSJ article. Again > the work is done outside of Csound and requires transferring the array > to an ftable. This would work, but it's a bit inconvenient compared > to having an opcode call within Csound code (at least, with the > workflow I'm using of editing UDO code within Vim and wanting to > visualize the results). > > I suppose I could just generate new ftables from the array data and > depend upon Csound built-in ftable plotting for what I was working on > for now. Setting up a Jupyter notebook may be something that could > work if I could also #include files within a %%csound magic command. > As it is now, I have my UDO code I'm working on, then a test.csd that > #includes the file. If the notebook can #include, the notebook could > take the place of the test.csd, which could be very interesting. > > Well, food for though! Thanks for mentioning this, I'll schedule some > time to setup ctcsound and Jupyter here and experiment with it. > > steven > > On Tue, Jul 19, 2016 at 1:36 PM, Francois PINOT |
Date | 2016-07-23 04:28 |
From | Steven Yi |
Subject | Re: Plotting Arrays |
Hi Ed, Thanks for sharing the website zip! I went to give it a try, but then realized I don't have the websocket opcode compiling here on WIndows. I'll have to study it on Linux or OSX when I next have a chance. I'm not sure it's quite what I was looking for since the code seems to be doing realtime spectrums, and I was looking for plotting static data so that I could compare with other static data. But the realtime stuff would probably come in handy for other projects. ;) Thanks! steven On Tue, Jul 19, 2016 at 6:24 PM, Ed Costello |
Date | 2016-07-23 04:30 |
From | Steven Yi |
Subject | Re: Plotting Arrays |
Thanks John, I hadn't thought of shelling out to simply run a command. That might be simpler to get working than debugging the python opcodes here on Windows (though the py opcodes idea by Victor would probably be simpler to use). I'll be sure to explore these options when I next need to do some plots. Thanks! steven On Thu, Jul 21, 2016 at 10:16 AM, jpff |