Re: [Matplotlib-users] Matplotlib & Basemap / What is the Best Graphical Back-end for Raster Data Display (.png) ?
Le 03/03/2016 15:43, Benjamin Root a écrit : > Matplotlib will not work at all without AGG. Even the AGG-less > backends still use AGG for image handling (imshow() and such). Is it so? I never found such strong statement in the docs. 1. SVG backend produces vector graphics, no rasterisation in principle, so why AGG? 2. Cairo uses its own engine. Why AGG? 3. Image (PNG) "production" from curves, etc. uses AntiGrain, but if imshow() shows an image which is just a pixel array, there is no manipulation needing AGG, an element (triple RGB) becomes a pixel, and that's it. Jerzy Karczmarczuk -- Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] TypeError: can't multiply sequence by non-int of type 'float'
Le 28/09/2015 21:03, Benjamin Root a écrit : > Where does he multiply a list by a float? The traceback shows the > multiplication happening much further down in the draw stack. Look, Benjamin Root, I don't know, and I will not "investigate" where this operation happens. The diagnosis is a standard Python message. Thus, I took the program of Shakhti Kannan, and in a few seconds I changed x = [1.0, 2.0, 3.0] into x = np.array([1.0, 2.0, 3.0]) and in update_line: x.append(1.0) into x=np.concatenate((x,[1.0])) And the program began to run without error messages. So, please, these are FACTS: somewhere the lists x,y,z get down in this draw stack. > That shouldn't matter. ax.plot() accepts lists as valid inputs and it > should be converting them into numpy arrays under the hood. There are two different issues, accepting any sequences/iterators is one, converting them into arrays - another one. This second operation visibly doesn't take place. J. Karczmarczuk -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] TypeError: can't multiply sequence by non-int of type 'float'
Shakhti Kannan tries to multiply a list by a float, and Python disagrees. Le 28/09/2015 17:43, Benjamin Root comments : > Could you file a bug report? This is going to need some investigating. == I suspect that it can be solved without Hercule Poirot. Convert *at the beginning* your lists x,y,z into np.arrays. (also: append ==> concatenate) Jerzy Karczmarczuk /Caen, France/. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] A request for a Matplotlib extension to hist
Le 24/04/2015 12:58, Christian Alis responds to the problem posed by Virgil Stokes > I had the same problem some time ago and what I did is to use bar() to > plot the histogram, which can be done in one line: > > hst, bin_edges = np.histogram(data) > plt.bar(bin_edges[:-1], hst) > > Perhaps this trick can be added in the documentation? > > I am willing to code Virgil's request if many will find this useful. Separating the computation of the histogram, and plotting it is obviously useful. (I needed this in a linguistical simulation context, where plotting had no sense). Actually hist is more or less this, see _axes.py, line 5678, the Axes method hist just calls numpy.histogram. And then plots bars (or uses some other style). So, although completing the documentation might be of general interest, I would NOT recommend adding some new version of hist. This would be misleading. Hist is hist is hist(ogram). It computes the histogram (and eventually plots it). If it is already computed elsewhere, naming the procedure which JUST plots some bars a "histogram" is methodologically very dubious. Jerzy Karczmarczuk -- One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] animation.FuncAnimation example --- how does it work?
Animation problem of Virgil Stokes. Since I began the answer sequence, here's a little more. If this overlaps other answers, I apologize. About the third parameter "/frames/ can be a generator, an iterable, or a number of frames." This makes very little sense to me --- what does "or a number of frames" mean? The name "data_gen" could suggest its meaning (after having read the doc). I am not sure what you are referencing as "the doc"; but I did read the documentation several times and English is my native language. I am not trying to accuse you of anything, I simply underline that if the documentation - as cited - mentions the word *generator*, and the program contains the argument *data_gen*, which is OBVIOUSLY a generator which *yields* some data, then this might have give you some clues concerning its meaning. Note please that the keyword parameters are specified extra. I am aware of this. Perhaps, I am a Python dummy --- when I see something like value = None in a Python API argument, I interpret this as a keyword argument and not a generator. 1. Generators might be or not function arguments, keyword or not; this is not an issue here. Generators are entities which produce iterators. Here you have: *def data_gen(): while True: yield np.random.rand(10)* , and this is all. 2. When you see "frames=None", etc., this doesn't absolutely mean that it is a kw parameter, just a positional parameter with a default value. Brendan Barnwell commented this already. If you look at the definition of the FuncAnimation class, which is readable, in the file ... matplotlib/animation.py, you will see *def __init__(self, fig, func, frames=None, init_func=None, fargs=None, save_count=None, **kwargs):** ** ...* which explicitly confirms this. I think that you got the answers you demanded. The FuncAnimation callback *requires* one argument, even if you don't use it. It may be the frame number (or index if you wish), or explicit, specific data, such as in your first example. If, as in your second example, the parameter passed is the frame index, and you want to see how you can use it, test this: *x=np.linspace(0,20,300)*** * def update(i):* ** ** *data=(np.sin(x+i/3)+1)/2* ** *line.set_ydata(data)* ** *** *** *ani = animation.FuncAnimation(fig, update, interval=40)* You should see a moving sinusoid. Please, in such cases test your programs by adding some simple tracing contraptions, say, print(data) inside update. I did this and more before posting my email. I would not have posted this unless I thought it was necessary. And I thought one purpose of this user group was to help people --- even if they ask a question which may be annoying or "stupid" in some subscribers opinion. I try to remember what a very wise teacher once said --- "there is no such thing as a stupid question". I don't understand your reaction. I teach computer science for many years, and several times per week I suggest to my students to do this, to trace their programs. I trace mine. Nobody feels offended. You said: data is undefined. But it WAS DEFINED, you agree? So, printing its value was the most natural suggestion. You would immediately see that it had been generated by data_gen. Also, I recommend that you look upon the sources of Matplotlib from time to time. I do it regularly, it is nicely commented, and complements very well the documentation. Jerzy Karczmarczuk PS. Some blizzard around positional/keyword parameters in Python is quite persistent. "Dive into Python" of Mark Pilgrim covers this, and offers some useful references. See also this : https://www.python.org/dev/peps/pep-3102/ -- BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] animation.FuncAnimation example --- how does it work?
Le 23/04/2015 12:22, Virgil Stokes a écrit : The following interesting example (random_data.py) is posted at: http://matplotlib.org/1.4.2/examples/animation/random_data.html import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np fig, ax = plt.subplots() line, = ax.plot(np.random.rand(10)) ax.set_ylim(0, 1) def update(data): line.set_ydata(data) return line, def data_gen(): while True: yield np.random.rand(10) ani = animation.FuncAnimation(fig, update, data_gen, interval=100) plt.show() This codes works; but, I am very confused by it. For example: 1. There are 3 positional arguments given for animation.FuncAnimation; but, in the API documentation for this class (http://matplotlib.org/api/animation_api.html), only two positional arguments are shown. The third one is the third one, "/frames/ can be a generator, an iterable, or a number of frames." The name "data_gen" could suggest its meaning (after having read the doc). Note please that the keyword parameters are specified extra. 2. data, the argument to the update function seems to be undefined. FuncAnimation usually passes the frame number: 0, 1, 2, ... as the first parameter of the update function, when "frames" is None, or the number of frames. If - as here - the third parameter is a generator, it passes the yielded data to update. It may be used or not. Please, in such cases test your programs by adding some simple tracing contraptions, say, print(data) inside update. Jerzy Karczmarczuk -- BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Best way to display image from URL in Python3
Le 20/03/2015 16:57, Ryan Nelson a écrit : > For me, if I change the script from the PR to what is shown below, > everything works fine in both Python 2.7 and 3.4 (Anaconda > environments, everything updated): > ## > url = 'http://www.libpng.org/pub/png/img_png/pngnow.png' > try: > import urllib2 > data = urllib2.urlopen(url) > except Exception: > import urllib.request > from io import BytesIO > data = BytesIO(urllib.request.urlopen(url).read()) > > from matplotlib import pyplot > > image = pyplot.imread(data) # crash on py3.x > pyplot.imshow(image) > pyplot.show() > # > But as you can see, the Python 3 version requires the addition of > BytesIO and read(). I take it that this is not supposed to be the case. It works for X.png, not for X.jpg. The call of imread() fails then. Tested also under 3.4/Anaconda. Jerzy Karczmarczuk -- Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Can not display 3D plot !
Le 13/11/2014 00:13, Geoffrey Mégardon a écrit : ... But to create the 3D axes, to draw in it, and then to show the figure, that crashes: from mpl_toolkits.mplot3d import axes3d import matplotlib matplotlib.use("agg") import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection='3d') X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z) ax.clabel(cset, fontsize=9, inline=1) plt.show() Basically on iPython QT console I would get an error like: ""Kernel died, restarting"" Perhaps it is your environment, not Matplotlib. A copy-paste of this program run without problems on my system. Anaconda 64 bits, IPython console (within Spyder). But *Windows 7*, not 8. Jerzy Karczmarczuk -- Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot arbitrary 3D surface
Le 01/11/2014 20:34, Benjamin Root a écrit : Actually, my response is still completely valid. You can only plot surfaces that can be represented parametrically in two dimensions. Find me a single plotting library that can do differently without having to get to this final step. 1. I did not claim that you said something invalid, only that it seemed weakly appropriate for Peter Karpedjiev. 2. Unfortunately NOW you say something inexact. Of course you can plot implicit surfaces without 2D parametrization. All the ray-tracing technology is adapted to that. POV-Ray, etc., if you want some names. Some terrain renderers, such as Terragen use it as well. YafaRay was once embeddable in Blender. I am sorry if the answer is unsatisfactory to you, but it is the correct one to give. 3. But "my satisfaction" is not the issue. I tried to direct Peter in some *usable* direction, according to my experience. Since the implementation of marching cubes, and other similar techniques is awkward, not very efficient in Python (I tried it), I suggest very strongly that Peter direct himself -at least temporarily - to the RT methods. If he wishes, I might help him in private. Writing a Ray Tracer in Python/numpy is not so difficult (I gave it as student projects a few times), and of course everything functional may be programmed in POV-Ray. Best regards. Jerzy K. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot arbitrary 3D surface
Le 01/11/2014 19:21, Benjamin Root answers the query of Peter Kerpedjiev, who wants to plot (with Matplotlib) the surface of an implicit surface (at least it was his presented example). Your comment "of course, plotting a sphere can be done in spherical coordinates" is actually the right thought process. Spherical coordinates is how you parametrize your spherical surface. Pick a coordinate system that is relevant to your problem at hand and use it. Sorry Ben, but this is not an answer. P.K. clearly states that his case is more complicated, and no parametrization is likely. Anyway, the spherical exercise as it is presented uses the 3D constraint, it is not parametric. The general solution is the *polygonization of the implicit surface*, which is a well established technology (although non-trivial). For example the /marching cubes / marching simplices/ algorithms and their variants. These are techniques for the polygonization of a mesh. If P.K. has an analytic formula for his distributions, and is able to compute gradients, etc., there are some more efficient techniques, but in general it is the case for solving the equation F(x,y,z)=0 for {x,y,z} ; here Matplotlib doesn't offer (yet) any tools if I am not mistaken. Jerzy Karczmarczuk Caen, France. -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] get_xlim of dates
Le 16/09/2014 17:31, Xiaobo Yang a écrit : > My X axis represents dates. When I used get_xlim(), I got something > like 735461.0 and 735490.5. What are these values? How can I convert > to python date objects? Please, read the documentation of datetime. Your data are *ordinals*, numbers which pack the data: year, month, etc. into one number ; the same strategy is used in spreadsheets, e.g., Excel. If r=r=735461, then datetime.fromordinal(r) gives: datetime.datetime(2014, 8, 16, 0, 0), unless I am mistaken... == This is the first approximation ... the "proleptic Gregorian ordinals" are integers. You have floats, and this probably is converted into fractions of a day / hour, etc. Read also something about timestamps. Regards. Jerzy Karczmarczuk -- Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce. Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Entropy calculation incorrect?
This is a side-remark. Please, don't exaggerate with the term "incorrect". Binary, decimal, natural... logarithms, all this is just a matter of multiplicative CONSTANT, and sometimes a question of convention. I am a physicist, and for "us" the entropy is NOT given in bits. We use natural logarithms, and in order to have the units appropriate for statistical physics / thermodynamics, we multiply the result by the Boltzmann constant, 1.38*10^(-23) Joule/Kelvin, and that's it. Anyway, Eric Firing is right, all this has nothing to do with Matplotlib. Best regards. Jerzy Karczmarczuk -- "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available. Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Intersecting polygons
Le 23/08/2013 03:32, Chris Beaumont a écrit : > It looks like some programs (like illustrator, and pdf2ps) are > semi-smart about handling transparency when converting to ps. Both > have their quirks (illustrator seems to mess up the bounding box, > pdf2ps makes the text look worse/fuzzy). > > Is this the recommended/best strategy? Who can really say what is a/the recommended strategy?... I am almost certain that the process described by Jon Ramsey - passing through jpeg - is better to be avoided. It probably works decently, and the JPEG is quite economic, but the conversion of a raster into EPS produces large files, and - as you said - the rasterization makes it not so scalable. And in general, a lossy compression is methodologically wrong here... I compared on a sample picture (similar to yours, but simpler, from the matplotlib documentation) these two methods: 1. Generate pdf, use pdf2ps (and convert to eps) 2. Generate svg, use inkscape to export eps. The results are visually comparable. I don't notice much of fuzziness; perhaps this is the anti-aliasing on your display? My version, the passage through svg produces a file which is more than 3 times shorter. Good luck. Jerzy Karczmarczuk PS. Try to convince the Dark Powers of the journal you send your work, that they modernize their processing and accept PDF. -- Introducing Performance Central, a new site from SourceForge and AppDynamics. Performance Central is your source for news, insights, analysis and resources for efficient Application Performance Management. Visit us today! http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Intersecting polygons
Chris Beaumont : > > I have a semitransparent plot that I rather like: ... > I'd like to publish something like this in a journal which requires > EPS figures. Unfortunately, EPS doesn't support transparency. > > How hard would it be to coax matplotlib (or another tool) to convert > this semi-transparent figure into a non-semitransparent figure that > looks the same? I won't claim that this is an ultimate solution, but what I did a few times was to 1. Choose the svg backend, savefig the picture as svg. 2. Open in Inkscape and export as .eps. The result was satisfactory. Jerzy Karczmarczuk -- Introducing Performance Central, a new site from SourceForge and AppDynamics. Performance Central is your source for news, insights, analysis and resources for efficient Application Performance Management. Visit us today! http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Evolution of the interface
Christophe BAL: I really appreciate the work done by matplotlib but I really think that the interface must evolve. Here is a small example. * object.set_something(...)* *object.get_something()* It could be easier to use a jQuery like style as in the following lines. *object(...)* *object()* This will considerably simplify things. Here is a more realistic example. *fig = pylab.figure()* *ax = fig.add_subplot(1,1,1)* * * *ax.set_xlabel(*"xLabel"*)* *ax.set_ylabel(*"yLabel"*)* The a jQuery like style would be as in the following lines. *fig = pylab.figure()* *ax = fig.add_subplot(1,1,1)* * * * ax(xlabel = *"xLabel"*, ylabel = *"yLabel"*)* * * I don't know enough matplotlib to propose other examples but I really think that *there is a lot **of things that could make * *matplotlib much more Pythonicly easy to use.* I am afraid I disagree a little bit. The call: object(...) [if object is an instance, not a class, otherwise ths would be a constructor] - - means object.call(...). Now, in principle one can throw inside a generic "call" plenty of attribute changes, but just imagine the parsing of all the possible argument combination. And, BTW, what would it mean: xxx= ax() ? In general case this is not practical. The methods in Python called.through.the.dot.notation are there to stay, I think. Jerzy Karczmarczuk Caen, France. -- Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_mar___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] bbox_inches='tight' from the navigation toolbar
Saurav Pathak: I would often save figures after show() from the savefig button on the navigation toolbar. I would like to trim white spaces using something akin to bbox_inches='tight', but haven't been able to figure out how. I tried adding the following to matplotlibrc, but to no avail. Adjust the position of your 'axes' rectangle, e. g. from pylab import * x=linspace(0,4*pi,500); y=sin(x) *axes([0.05,0.05,0.93,0.92])* plot(x,y); show() the details will depend on the size of your labels. == Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] y-axis misbehavior
Le 11/06/2012 22:30, magurling a écrit : > I just wanted the axis line to end at the last y tick > I've never used an explicit axis. What will axis('tight') actually do? In your case plt.axis('tight') will constrain the axes to your plotted object, no space above, below, or at the right. The "good" plot gives x from 0 to 0.10, and y from -20.5 to 69. (The other: to 70). The tight_layout directive is used mainly when you have several subplots. Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pdf/eps export; dotted line plot shows random markers on the line
Benjamin Jonen: > I get random markers on the > line. This effect appears for pdf but not for png. When I use eps and > convert the eps file to pdf I also receive the random markers. > ... For me your PDF is OK, nothing "broken". I get exactly the same (mpl 1.1.0, on Windows XP, Python 2.7). Your problem has probably nothing to do with matplotlib... Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] y-axis misbehavior
Mark Gurling: > > I have two bar graph scripts (good.py and bad.py). ... > while in good.py the y-axis ends precisely at -30.0, in bad.py the > y-axis ends below -30.0 despite the yticks setting specified on line > 20. Is there an explanation for this behavior? How might I remedy this? What do you really want? Tony Yu tries to explain the behaviour. I would suggest using an explicit axis, e.g. plt.axis([0,0.10,-25,80]) (or between -30 and 100, or 'tight', etc.) Perhaps you wanted axis('tight') rather than your tight_layout? Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How to draw a curve until it intersects another curve
Gordon Hardmant : > I ...cannot find a simple way to stop a curve being drawn once it crosses > another curve. In the attached example, I am trying to draw the solid > curve only until it intersects the dashed one. I have tried using the > numpy.where() method, but it does not seem to be the right way to go > about it- I end up having to write FOR loops and so on, and that does > not make use of the vectorization advantages of numpy. Try to insert just before plot(...) the following two lines: igc=np.sign(ig_bdry-ig_d2) ig_d2[igc!=igc[1] ]=np.nan This [1] is a place which discriminates where the difference sign is "good". Of course this will produce some bedlam if there are many intersections. You didn't say whether you want to plot the dashed curve entirely. If not, just truncate all three, the solid, the dashed and the abscissa, where the sign is OK. Good luck. Jerzy Karczmarczuk Caen, France -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dark or inverted color scheme
Tony Yu: # rc definitions for dark backgrounds lines.color: white patch.edgecolor: white ... don't forget to lighten the colours in axes.color_cycle (unless blue on black, etc. suits you). This is used by plot and was one of my numerous mistakes two days ago... Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] matplotlibrc interpretation seems buggy : SORRY
I wrote: mpl.rcParams['lines.color'] = 'r' ... ...the line is still blue. BR answers: Plot() doesn't use lines.color. I don't remember the exact name, but it uses an rcparam for color cycling. Just change make the list of colors be just 'r'. [*!#!!%*!!] Of course I found that myself some time after reporting this "bug"... Sorry. The parameter is "axes.color_cycle" Jerzy K. -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] matplotlibrc interpretation under Windows seems buggy
Gurus, Windows XP, matplotlib 1.1.0. Backend Tk, but the same elsewhere. Programme: import matplotlib as mpl import matplotlib.pyplot as plt mpl.rcParams['lines.linewidth'] = 2 mpl.rcParams['lines.color'] = 'r' x=range(800) y=[t for t in x] plt.plot(x,y) plt.show() # == Linewidth OK, equal to 2, but the line is still blue. Changing "r" to red, or to #ff, or (1,0,0) doesn't change anything, still blue. Changing directly the matplotlibrc file (default) - the same. Leaving in peace the defaults, constructing another rc in the working dir - the same. The dictionary rcParams contains the correct value 'lines.color': 'r' (Anyway, rcsetup.py validation doesn't protest. But then, the modified colour is ignored). Somebody could confirm that? The best. Jerzy Karczmarczuk Caen, France -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] how to remove colorbar?
Benjamin Root : > Colorbars are a bit tricky. They are actually a subplot axes separate > from your plotting axes. And I don't think they are very easy to > remove. You could do a "cbar.axes.cla()", but that would still leave > the "ticks", tick labels and the colorbar label. > > I am sure that there is a way to get to what you want, but it isn't > immediately obvious. Well, I tried with some success the following. Suppose the programme is: from pylab import * fig = figure() ax = fig.add_subplot(111) data = rand(250, 250) cax = ax.imshow(data) cbar = fig.colorbar(cax) show() Now, fig has two axes, the main, and the bar. The command fig.delaxes(fig.axes[1]) gets rid of the bar and the ticks. Is there anything wrong with that? Of course, I knew that fig.axes[1] was the bar, but finding it in a more complicated case should not be difficult. All the best. Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] basemap and fill_between()
Appendix. (and excuses for my approximate syntax in the first message; I was doing three things simultaneously). Maestro David Craig, your filling will be lousy anyway. If your x and y arrays come from linespace, you will surely get a triangle, and not the curvilinear area between GreatCircles. You must transform the coordinates in a more clever (but equally easy...) way. Jerzy K. -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] basemap and fill_between()
Le 13/05/2012 11:34, David Craig a écrit : > Hi, I'm having a problem usinf fill_between() with basemap. I plot two > great circles and want to shade the region between them. My code is > below, it doesnt give any error just creates the plot without filling > the area. Does anyone know if it's possible to do this or should I try > a different method? Hello, Boss. Perhaps I am telling rubbish, but fill_between demands the coordinates within your axes, not the basemap angles. Your a,b,c contain some small numers (negative x, say -38) won't do any good, x should be, say 3001129 etc. Use m(...) to convert. Jerzy K -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Pick event
(13/05/2012 02:52), Arek Kędzior: > What I am trying is to plot multiple discontinuous lines. > I know that this approach does not work very well. How about > using LineCollection. > Put all curves into line collection > Use Pick event to get line segment (what function to use ?) > Once I have line segment, get xdata, ydata corresponding to line > segment (what function to use ?) Why don't you use: picker=myTest in your ax.plot, where def myTest(artist,mousevnt): ... return (hit,kwdict) performs any test you like? Again, this is called separately for every Artist belonging to the Usual Suspects, but you may control whether this is the first line found, then your program just computes the distance, or the second one, then it computes the distance, and discriminates between the two. The properties kwdict passed to your callback will permit to do the rest. Or, perhaps, the first time the test doesn't do anything, and returns False, and the second time computes both distances, and finds the minimum. You have your "private" access to both lines anyway. The generalization to many lines should be straightforward. Jerzy K. -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pick event
Arek Ke;dzior: If you pick one of the curves in the close location to tangancy area, the OnPick function will be executed twice (2 curves) and will display 2 markers. I want to find the shortest distance from the pick location (mouse coord.) to a discrete point on the curve and draw marker on the curve at this location (only one). See the line with "print lineObj" Ok, now I -- perhaps -- understand. This is a speculation... Your approach cannot work, since the low level event handling issues TWO pick events, one for each curve. Everything works very well, your program finds the appropriate point ... on both curves, separately. I suggest that you try to react to lower level mouse events. Look into the Pick code within the Artist class. The system tries to pick all the children, and here - I believe - resides your problem. You should perhaps discriminate the picked target at this point. Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] pick event
Arek Ke;dzior: I am trying to use pick event. ... What am I doing wrong ? Wrong with WHAT? What do you expect? Jerzy Karczmarczuk -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Strange behaviour of scatter with single-column 2D array
LJulien Rebetez : > I've run into a strange behaviour of matplotlib while trying to figure > out why my data was displayed incorrectly. > I'm note quite sure if this is a bug or expected behaviour, but I feel > it's kind of counter-intuitive, so I'm posting here. > > ... > Now there seem to be a difference on how numpy handles A[:,0] > depending on if A is a np.array or np.matrix. In the case of > an array, a 1D array is returned, in the case of a matrix, a 2D Nx1 > matrix is returned. Using this matrix seems to confuse matplotlib. > > Using np.ravel or np.flatten on the slices fix that problem. > > Is there an explanation for this behaviour or should I fill a bug ? Don't fill a bug. Read http://www.scipy.org/Tentative_NumPy_Tutorial , please. They explain that a slice of a matrix is a matrix, and its "view" is different from what you get for arrays. But, no need to reshape the stuff. Just use the "array attribute" of the matrix : pl.scatter(B.A[:,0], B.A[:,1], c='b') //Here 'A' is the name of the attribute, nothing to do with your array A; by chance it is the same...// The best Jerzy Karczmarczuk -- This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] histogram and a line
Mic : Thank you for your solutions. However, with my dataset it did not work out with the following code: ... Please find attached the histogram. The dataset I am sending with next email. 1. You haven'sent *in.small.txt*, but *in.txt*, 70 MB, several millions lines. Please, be gentle wrt people who want to help you and are obliged to test your stuff. 2. You file is buggy, last two lines generate an exception. They contain a text "mean ...". 3. I corrected them, the program works, and gives the picture you attached. You don't say WHAT is "not working". Is it the question of scaling, or something else? 4 If it is scaling, and IF IF ... you want to obtain something I attach, then use the code: *hst=axes.hist(data, bins=50, normed=True) mxh=max(hst[0]) plt.plot([mean,mean],[0,mxh],'r',lw=2) * 5. Learn something about WHAT is a normed histogram in matplotlib, how to get into the plotted data, and to adjust the scales. Otherwise such problems will repeat. 6. Finally, in our civilized world people sign their messages. Anonymous letters are ugly. Jerzy Karczmarczuk -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Changing a single marker on a line
federico vaggi: I am drawing a line with n points, using a particle marker - something like: x = np.linspace(1,10,11) ** 2 y = np.linspace(1,10,11) ZZZ=plot(x,y,'ro') Is there any way to change the 7th dot (7, 49) to be a blue star instead of a red circle? I was considering using the scatter function to scatter points 1:6 and 8:10 separately with 'ro' and then scatter 7 with the right properties... is that the easiest way? I might be silly, but I believe that this IS the easiest way. In the program above ZZZ (which I put myself) is a list containing just ONE Line2D object, with a common set of properties, such as set_markerfacecolor() or set_marker_size(), and if you use them, all markers change. The data attached to the plot have no information about markers. So, if a way exists at all, to change just one marker, it would be quite involved, and a second plot seems easier than anything else. But a true specialist might know The Real Magic... Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] histogram and a line
Nicolas Rougier, (to Mic, who can't see a histogram and a line simultaneously): > You need to specify the ylim because your height may be larger than your > histogram and then you cannot see it. I suspect something similar. The height of matplot_hist.png is 0.040. The line goes from 0 to 300. The histogram reduces to the bottom line. There is no immediate relation between max(hist_data) and the height of a *normed* histogram. And, please, if you want to point out the difficulties in making your programs fulfil your aims, show the REAL, COMPLETE programs, perhaps with fake, random data, but without useless : "hist_data=[]" And don't call a mean: "median" or vice-versa... Scaling the axes is easy. "ylim" should be changed, use also the "extent" parameter (see doc). Drawing axes shifted, as in hist.png is a bit more involved, and I don't know if you really want that as well. Jerzy K. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] histogram and a line
Mic: Hello, I am able to draw a histogram with the following code: /.../ /h.hist(hist_data, bins=50, normed=True)/ However, I don't know how to draw a line for median at 249 position like in attachment. Are your axes really matplotlib axes? (I have doubts, since the vertical is not normed, although your histogram is). In your real axes, the command plot([249,249],[0,height]) draws a vertical line (there is a primitive vert. line as well), what is the problem?? Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] backend with edition capabilities
Andrea Gavana : > Anyway, if I am not completely off-track, this is something I had been > looking for as well in matplotlib a while back (3, 4 years ago), but > at that time I was told it would have been complicated to implement it > for all the "live" backend (I can't recall the exact reason). > > I would say that, at least for the backends based on wxPython, this > kind of modify-the-live-plot-via-GUI-interaction should be relatively > straightforward, at least for the GUI part and for the basics (line > styles, colours, markers and so on). There is one non-trivial difference between Matplotlib and Matlab. Matplotlib is "just" a library, and not an integrated package with its own event processing loop, multithreading, etc. When you plot() something under Matlab or Scilab, you generate some objecs (gcf, gca) and other stuff, accessible from outside. Your program turns normally, your console works. So, you may launch a procedure which analyses all the plotted data and change the "patches", "lines", "collections", etc., using the matplotlib jargon. In matplotlib, upon show(), you relinquish the control. The interaction becomes clumsy, the animation becomes clumsy, since matplotlib doesn't give you the full access to the event loop. OF COURSE you may do it, but it will require some work. One possibility is to use an interface which by design works (I presume...) in a separate, non-blocking thread. I mean: IPython. If you launch IPython --pylab, then you may, e.g. construct: x=linspace(0.0,25.0,300); y=sin(x) plot(x,y) and the figure is created without show(). Then, write: a=gca(); p=a.lines[0] and nothing more difficult than: p.set_lw(3); p.set_color('red'); draw() You have edited your line. No need to change the code of matplotlib. Good luck. Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] draw lines in basemap
David Craig : > I'm trying to produce a map with 12 locations marked on it and straight > lines plotted between each point and all other points on the map. I have > the map with the locations ok but am having trouble getting the lines. > My code is below anyone know how to do this?? > ... > for i in range(len(lons)): > for j in range(len(lons)): > if i == j: continue > m.plot([x[i],y[i]],[x[j],y[j]],'k') I am not sure what do you really want, but perhaps replace the last cited line by: m.plot([x[i],x[j]],[y[i],y[j]],'k') == All the best. Jerzy Karczmarczuk Caen, France -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Matplotlib gallery
Nicolas Rougier : > I've seen the discussion around the re-organization of the matplotlib gallery. > If that might help, here is a link to a small gallery I made. > > The overall organization is simply based on subdirectories so maybe it could > be a (temporary) solution for the matplotlib gallery (just matter of moving > examples in the right subdirectory). THANKS, Nicolas. This is a nice initiative, but I believe that in the context of a presentation of some software, this is not the way I would have chosen. Why people look-up /such/ galleries? Why I do it myself? What are the needs of my students (about 20 - 30 guys who work with matplotlib week after wek)? Often because I want to find a concrete program, which answers a concrete question : how to implement timed animations. How to make multiple plots. How to insert a figure in a GUI with widgets, how to distort an image matrix, etc. etc. So a gallery should contains infos about what the hell the example XYZ is about, what does it show, where is the *concrete* documentation page with the description of the tools used, etc. The order of examples should be rational, and as ALWAYS some cross-links would be useful. Program-sources without comments are not so useful... == But I believe that this is just a start, and I am aware that to criticize is easier than to do something. (Je suis un grognon né, Nicolas, désolé...). So please, continue, my heart is with you! Jerzy Karczmarczuk Caen, France. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Ploting a sparse matrix with imshow
Jeff Whitakert : Jose Guzman: ... >>> imshow(W, cmap=cm.binary) # W is a Numpy Array with shape (100,100) However, this does not work the way i would like (the ones appear very blur). I would need the correct representation of a grid where the possition 0,0 is simply the entry W[0,0] of my array. Jose: I think you need to add interpolation='nearest' to get rid of the blurriness. A. This is one possibility. B. The - mentioned previously - matshow, is another one. C. figimage(W,cmap=cm.binary) is a third one ; here the scale is one to one in pixels, independently of the figsize. D. Specific backend image plotting is yet another one, if somebody needs really to work hard. Jerzy K. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Enjoy all them spammers
I believe that the list owners will have to strenghten some tools to fight against all those shameless spammers. Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] key_press_events in matplotlib embedded in pyqt4
Saurav Pathak : > I am trying to generate key press events in matplotlib (imshow) embedded > in pyqt4, but I am getting nowhere. Yes, another victim... My small animation test program http://users.info.unicaen.fr/~karczma/TEACH/Test/isingVZ.py run under Windows XP / Python 2.7, shows the following 1. For WX and GTK the timing doesn't work properly. 2. For QT4 key event processing doesn't work Only Ye Olde Tkinter backend seems to behave decently. Well, the animation in matplotlib - as I have already mentioned some week ago - is really imperfect, and should be re-analysed (in particular not giving to the user the access to the event loop is a severe handycap). Now I see that events in general need to be looked into in details. I feel sorry that I have no time to dig more thoroughly. (Of course, I may be doing some rubbish..., then mes plus plates excuses). Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Dynamically adjusting the color scale in NonUniformImage
Ray Osborn: OK - it turns out I can reproduce it in a simple ipython session using ipython --pylab=qt. I set up an image plot as follows: import numpy as np import matplotlib.pyplot as plt from matplotlib.image import NonUniformImage x=y=np.linspace(0,2*np.pi,101) X,Y=np.meshgrid(x,y) z=sin(X)*sin(Y) ax=plt.gca() extent = (x[0],x[-1],y[0],y[-1]) im = NonUniformImage(ax, extent=extent, origin=None) im.set_data(x,y,z) ax.images.append(im) ax.set_xlim(x[0],x[-1]) ax.set_ylim(y[0],y[-1]) plt.colorbar(im) plt.gcf().canvas.draw() After that, I try to change the color scale using: im.set_clim(0,0.5) plt.gcf().canvas.draw() The colorbar changes scale, but the plot is untouched. Is that the expected behavior? Thanks, Ray Try, perhaps, after set_clim, to reinstall the data: im.set_data(x,y,z) plt.gcf().canvas.draw() = Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] "Visually equivalent" contours/parallels
Andrea Gavana continues to struggle with his parallel lines: > I managed to get *almost* there, but there still is a small glitch. I > attach a self-evident sample, which generates data very similar to the > real ones I have and shows the two "parallel" curves to the main one. > > You will notice that the "parallel" curves look parallel almost all > the time, except in a few areas (I have annotated the plot for > reference). I can't see the reason for this difference, but it is > obvious I am missing something. Yes. I am afraid it it not a small glitch, but a serious bug. Actually, there are still two things. The second one is the purely visual scaling based on the aspect of your figure on the screen, and I will not discuss it now, you can get into your axes, pick the frame, dig out the extent, extract the "points" of the rectangle, and do some other dirty stuff, which will get wrong when you touch your figure... So, here - I believe - is better to adjust things by hand. But the REAL STUFF is elsewhere. You added a vertical scaling, as I suggested, based on the aspect ratio of your data. You rescaled the offsets. I believe that I might have suggested that, if this is the case, I am sorry, it was a mental abbreviation... Rescaling JUST the offsets, and keeping the function itself in a "distorted frame" is sinful. Here you are another attempt. With (or without) your permission, I reconstruct the offset without your !*##$%*!! arctan... This is my equivalent of your "get-normal points" : def adp(x): # This computes the derivative without splines or other heavy artillery. xa=numpy.concatenate(([2*x[0]-x[1]],x,[2*x[-1]-x[-2]])) return xa[2:]-xa[:-2] def para(x,y,dst,ax): # ax is the current axes set, dst is the offset. scal=ax.get_data_ratio() # Don't send human make the work of a machine! y0=y/scal # Warp the original dx=adp(x); dy=adp(y0) ds=dst/numpy.sqrt(dx*dx+dy*dy) x1=x-ds*dy; x2=x+ds*dy y1=y0+ds*dx; y2=y0-ds*dx return (x1,y1*scal,x2,y2*scal) As you see, the function got "undistorted", the offsets calculated, and Mister Sulu, get us back into the real space ! Now, within your main() : ... fig = plt.figure(figsize=(fw,fh)) # whatever... ax = plt.subplot(111) ax.plot(x, y, color='orange', ls='-', lw=3, label='data', zorder=30) # It should be done first ... ax.set_xlim(xlims) ax.set_ylim(ylims) ax.grid() ax.invert_yaxis() ... xh,yh,xl,yl = para(x,y,distance,ax) # Here you are. ax.plot(xl, yl, 'g-',zorder=30) ax.plot(xh, yh, 'b-',zorder=30) = OK, let's get back to the second problem. Here you have the additional scaling. def vscal(ax): gf=ax.get_frame() ex=gf.get_extents() po=ex.get_points() # What a lousy way ! Probably Ben R. knows some more direct access. w,h = po[1,0]-po[0,0], po[1,1]-po[0,1] return h/w And within para(), the first line becomes: scal=ax.get_data_ratio()/vscal(ax) However, since my insomnia doesn't necessarily mean that I am fully conscious, check everything twice. Add your fig.subplots_adjust, and recheck. Good luck. Jerzy K. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Axes Scaling
Francois Lemery : > Hi Python World! > > I currently have a 2D array: A[i][j] which I can plot very nicely > using the contourf function. However, in this plot, the axes span > from (0, i) and (0, j). > I would like to multiply each axes by a scaling constant- thereby > turning the array element values into physical quantities (distance > and time for example). > Could anyone help me with this? I've looked around, but so far the > only solution I have found is to create a new set of arrays with these > scaling factors included. I can do this, but I feel as though it > would be a waste. You want just to change your labelling? No problemo, Baby. xmin,xmax = ymin,ymax = ... tbl=... ic=contourf(tbl, extent=(xmin,xmax,ymin,ymax)) axis([xmin,xmax,ymin,ymax]) show() Bon courage. Now, if you want to change your *values*, as Alexa understood, then be more precise, please. Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] svg in plot
Benjamin Root : > it would be impossible to fully implement, such a module would never > be included in matplotlib, but that shouldn't stop someone from > creating a useful basic tool. Yes. Thank you Ben. I so concentrated on the "vector" side of the original question that I forgot that AGG has a rasterizer and filters, and morover Matplotlib can rescale (regenerate) bitmaps when resizing the figure! OK. Since the ActiveState cookbook http://code.activestate.com/recipes/325823-draw-svg-images-in-python/ offers some programme to draw SVGs, and the SVG parsers are doable, somebody might start tomorrow. Great! Jerzy K. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] svg in plot
I forgot to add something... Benjamin Root : > There is absolutely no reason why a module could not be made for this, > given that everything in matplotlib is assumed to be vector-based. > You just need a library that can load up the data in the SVG file into > information that is sensibly organized. In principle a decent parser can be added to Matplotlib. But... SVG is NOT entirely a vector drawing program!! 1. You have gradients, clipping paths, patterns, and filtering, which interpolates between vector and raster data. You will not implement easily as an "artist" the blur, displacement maps, or morphologic filters 2. SMIL style animation needs a specific engine, this will not easily work on a back-end independent framework. == Usually I hate people who discourage others, or say that something cannot be done. But here, such a module would take too long to implement, and the gain seems not adequate. I would be VERY HAPPY, if I am wrong. Jerzy K. -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] svg in plot
William Hoburg: > Is there a way to import a svg-image into a plot? > I know that there are some possibilities to import png > (http://matplotlib.sourceforge.net/examples/pylab_examples/demo_annotation_box.html) > or eps (which is then rastered). > But till now I didn't find any way to import/embed a real vector graphic > which is still a vector when I save the figure again as pdf or svg. SVG is a text file, a quite complicated XML. In order to put it into a canvas you have to parse it, and to transform all the DEFs, the primitives and attributes into plotting commands. Such package as matplotlib lives in anther galaxy. It took a lot of time to implement SVG in Mozilla or Chrome... Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Fwd: Re: Colobar and change axis x and y labels
"Pythphys", would it be too demanding to ask you to sign your messages with a human name?... Danke. You ask: > - changing to an image grey scale only needs ... what? plt.set_cmap(plt.cm.gray) in the context of your current figure. Or, use cmap=... in your imshow. Please, look up "colormap" in the documentation. > - I need to do a 'plane fit' of the image. Does matplotlib > have some routine for this? Or shall I use other math libs? I am not a guru of matplotlib, but this is a visualisation package, not a data processing one. Scipy (numpy) have some interpolation procedures, polyfit, etc. but I don't remember without digging the docs (which you might do as well) whether multidimensional fitting is there. Anyway, why not use your head? This is a standard student exercise. You need to fit: zf = ax + by + c, having z =f(x,y) in your image, am I right? If not, forget the rest. Use the linear regression, find the zero of the gradient wrt (a,b,c) of SUM[(ax +by +c - z)^2] and that's all. The most tragic part of the exercise is the necessity of solving a linear equation set in 3 variables... Jerzy Karczmarczuk Caen, France -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Colobar and change axis x and y labels
Le 16/02/2012 02:20, Alexa Villaume a écrit : > Try using 'xticks' and 'yticks', those commands let you define the > location and label fo your tick marks. > This *alone* will not do, the image might be scaled badly. Add extent. Try this: fig = plt.figure() frame = plt.subplot(111) im=frame.imshow(data,extent=[0,3400,0,3400]) plt.xticks([0,3400]); plt.yticks([0,3400]) plt.xlabel('X (nm)') plt.ylabel('Y (nm)') plt.colorbar(im) plt.show() == Jerzy Karczmarczuk Caen, France -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot as individual "colorbars"
Could you provide a /working/ example with the geometry you really want? I believe I thought more or less about it as Tony Yu did. If it is wrong, be more precise, please. Jerzy Karczmarczuk -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] "Visually equivalent" contours/parallels
Andrea, I believe that if you find ONE good visual aspect ratio, according to your figure size, that should do. Yo know your figsize, and if you know all in your axes([bot,lft,wid, height]), that this visual ratio should be easy to fix. BTW, I did not understand why do you play with your "angle" = arctan(...), then compute sin and cos, etc. Two issues. 1. You are wasting your time. 2. If your data is a functional sequence, with x growing, its OK, but for ANY data you may get zero in the denominator, and your arctan will locally explode, producing holes in the plotted data. Use arctan2. Or rather, don't compute angles at all. Concerning 1. If you compute dx = xhigh-xlow; dy=yhigh-ylow; then the parameters of a normal offset are (nx,ny) = (-dy,dx), appropriately normalized, and that's all. All the best. Jerzy -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] "Visually equivalent" contours/parallels
Andrea Gavana : > after some great help from the Numpy users list, I have managed to > create "parallel curves". > > > But I can't really do that with the set of data I have, as the X and Y > variables have different order of magnitude and I need a single > subplot on the figure to have rectangular axes (not square). (...) > So, my question would be: how do I scale the > X and Y vectors so that the parallels look parallel to the main curve > even if the axes are not square and the X and Y variables have > different data-ranges/magnitudes? Andrea, you have TWO problems. The first is to scale your offset according to your axes range. This can be done using ax.get_data_ratio(). In your case you will get 5, and this factor should enhance your vertical offset wrt. the horizontal. (Or, use .get_xlim() and .get_ylim() and do the computations yourself). The second problem is that your FIGURE scales your plot visually, independently of your axes, so without special scaling it will have different aspects according to your manipulation. An arbitrary affine transform will keep straight lines parallel, but no chance with arbitrary curves. You may play with fig.get_figwidth(), etc., but here my digging stops. Good luck. Jerzy Karczmarczuk -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Polygon contains_point() different from matplotlib.nxutils.points_inside_poly?
reckoner: >>> th= array([ 4.65542641, 5.32920696, 2.20928291]) >>> p=patch.Polygon(array([cos(th),sin(th)]).T) >>> print p.contains_point((0,0)) 1 >>> print matplotlib.nxutils.pnpoly(0,0,p.get_path().vertices) 0 Thanks! I can confirm this for both the current development branch and v1.1.x. Strange Ben Root HYPOTHESIS (I have no time to check now everything..., I did my best.) If radius=None, it is converted into radius=1 in contains_point (in Patch). (This is the linewidth !) I am not sure whether it is ok, i.e. in pixels. If this value is considered to be relative to axes, it is enormous! p.contains_point((0,0),radius=0.01) gives 0 as it should. Jerzy Karczmarczuk P.S. I suggest anyway that reckoner submits a complete program with imports. What is "patch"?? -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Polygon contains_point() different from matplotlib.nxutils.points_inside_poly?
Le 13/02/2012 17:47, reckoner a écrit : I'm trying to test whether or not the origin is contained inside the following triangle inscribed inside a circle: > th = array([ 2.3913423, 5.3133123, 1.8516171]) > p=patch.Polygon(array([cos(th),sin(th)]).T) What do you mean by "patch" here? I tested p=Polygon(array([cos(th),sin(th)]).T) p.contains_point((0,0)) and the answer is 1. Jerzy Karczmarczuk -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] problem to plot constant limited(within specific xrange value) y line within a square well
Debashish Saha : > ... > > Question: > then how to plot those specific component of E within the square well only? Why not: for m in E: plt.plot([-a,a],[m,m],'r') plt.show() Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Missing Segments in Output of imshow()
Christopher Ellison : > Taking the image size to (30,30) made all the segments appear, but their > thickness was still not uniform. Using some sort of smoothing helped, > but it still not displaying what the matrix was specified as: a set of > blocks, somewhat resembling a line, all of which are the same color and > thickness. > > Can I have matplotlib show the matrix as I have specified it? Or is > that too naive (on my part)? Thickness is not uniform, since the system MUST truncate something when you code your drawing as you do. With sinc or bilinear interpolation you will see non-uniform shades of gray. Bicubic interpolation will be - probably - much better. But if you want to see your matrix as you want to see it, don't use imshow. Use figimage. plt.figure(figsize=(7.5,7.5)) plt.figimage(x,cmap=plt.cm.gray_r) And, for goodness sake... Don't shoot yourself in the foot by savefig, which stores not the matrix, but the figure, the drawing of it after all the calamities. Use plt.imsave('bug.png',x,cmap=plt.cm.gray_r) Good luck. Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Missing Segments in Output of imshow()
> I am experiencing missing "segments" in the output of imshow() > > Here is a minimal example: > > I have attached an example of the output. In theory, there should be > a continuous line from the left side of the picture to the right side. > The problem seems to occur across backends. Additionally, the > thickness of the segments is not uniform. Some are thinner than the > rest. Decreasing the value of N seems to make the issue go away. > Increasing the value of N makes the problem worse. > > Any ideas on what is going on and how I can fix it? > Imshow scales your geometry according to the figure size, and if you *insist* on having the "nearest" interpolation, you may lose pixels while drawing, it is as simple as that. No miracles. How to fix it? 1. Use bilinear, or sinc, or any smooth interpolation. 2. Make your figure big enough, say plt.figure(figsize=(14,14)). Jerzy Karczmarczuk -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How Clear Points Without Wiping Everything?
Benjamin Root on my suggestion that one can use del instead of remove : There are methods for ax that properly handle removal of types of artists that have been attached to an axes. The above approach assumes that no other collections have been plotted that you wanted to keep. The approach I gave is a very surgical method that makes sure that only what is supposed to be removed gets removed. Both are valid, and their usefulness depends upon which view of the data you need (remove types of artists versus removing particular artists). Yes, absolutely. With just a little remark: remove is a Python function which *searches* the list for a given value. del uses indices, so del lst[1] will be most probably faster than lst.remove(value), if this value happens to occur for the first time at index 1. Unless Matplotlib uses a specially tuned version of remove. Under Windows XP, ion() is not too compatible with show(). TKAgg (by default), WXAgg and GTKAgg bomb Bens program (and without draw() nothing is plotted). That would be a bug and should be reported (assuming that it is in the latest version). Make sure that you are using at least v1.0.1 (preferably v1.1.0) to make sure that show() should do what you want. Any version earlier than v1.0.1 is very unpredictable with respect to multiple show() calls. I use 1.1.0. (Python 2.7.2) I didn't report any bug because I didn't know whether this was a bug... But there are more... The animation module uses various timers depending on the back-end. This is -- perhaps -- the result of the fact that Python standard Timer (a subclass of Thread) is, to say it mildly, rather weak. So, under Tk the system uses after(), wx offers its timers, etc. Timed animation works differently under various backends. Here: http://users.info.unicaen.fr/~karczma/TEACH/Test/isingVZ.py is a program which simulates/visualizes a simple-minded 2D Ising model (vectorized Metropolis Monte-Carlo; not *exactly* physical, but only mister Nobody is perfect...). It should update the picture dynamically, and my students can see how the ferromagnetic domains develop. When run with Tk, OK. GTK and wx -- no. The animation runs, but the figure is frozen for many seconds, and it is updated when the Slider is activated. The autonomous refreshing of the image is much much slower than under TK. I don' understand what is happening... Tested on Windows XP, and under Linux (Fedora). I repeat, the animation runs, this is a problem of refreshing the display. Thank you, and all the best. Jerzy Karczmarczuk -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] How Clear Points Without Wiping Everything?
Benjamin Root : > Just about any mpl plotting function (plot(), scatter(), hist(), etc.) > returns an object. Most of the time, users do not save the result > into a variable, but if you want to do advanced tricks, you will need > to save those returns. Sorry for a shameless attempt to add something to this, but actually here you don't need it, these collections are accessible through the current axes: plt.plot([0, 1, 2, 3, 4], [4, 3, 2, 1, 0]) pts = plt.scatter([1, 2, 3], [1, 2, 3]) ax=plt.gca() ... del ax.collections[:] (Or, say, del ax.lines[:] to remove the first line ; I do it often when I plot a solution of a differential equation, a trajectory, keeping just a few last segments). == This reminds me a nuisance... Under Windows XP, ion() is not too compatible with show(). TKAgg (by default), WXAgg and GTKAgg bomb Bens program (and without draw() nothing is plotted). Jerzy Karczmarczuk -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] psd
David Craig : > Hi, thanks for that. I've made the following changes: > > NFFT = 100*60*10# Linked to window size > Fs = stream[0].stats.sampling_rate > win = np.hanning(NFFT) > overlap = NFFT/2 > power, freq = plt.psd(data, NFFT, Fs, win, overlap) > > but it returns the following error: > > Traceback (most recent call last): > File "/home/davcra/Desktop/python_scripts/welchPSD.py", line 20, in > > power, freq = plt.psd(data, NFFT, Fs, win, overlap) > File "/usr/lib/python2.7/site-packages/matplotlib/pyplot.py", line > 2322, in psd > ret = ax.psd(x, NFFT, Fs, Fc, detrend, window, noverlap, pad_to, > sides, scale_by_freq, **kwargs) > File "/usr/lib/python2.7/site-packages/matplotlib/axes.py", line > 7876, in psd > sides, scale_by_freq) > File "/usr/lib/python2.7/site-packages/matplotlib/mlab.py", line > 389, in psd > scale_by_freq) > File "/usr/lib/python2.7/site-packages/matplotlib/mlab.py", line > 419, in csd > noverlap, pad_to, sides, scale_by_freq) > File "/usr/lib/python2.7/site-packages/matplotlib/mlab.py", line > 268, in _spectral_helper > thisX = windowVals * detrend(thisX) > TypeError: 'int' object is not callable Please, look the syntax of .psd in http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=psd#matplotlib.pyplot.psd You will find, for example, that the 5th argument, detrend, should be callable. In your code it is just a number. Use explicit keywords, it may save you from misunderstanding yourself... Jerzy Karczmarczuk OH. Fabrice Silva found it as well. OK, two is better than one... -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
Fernando Perez: > I now see there's even a pause() call: > > https://github.com/matplotlib/matplotlib/pull/148 > > so it seems like it should be an easy matter of adding the button and > wire it to pause(). This is a temporal pause, not an undetermined suspension, restartable. Jerzy -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
Fernando Perez : The lack of a clean pause/restart functionality is indeed problematic. Furthermore, closing a window that's running an animation, at least with the Qt backend, gave rise to a massive swarm of 'C++ object has been deleted' messages flooding the console where my ipython kernel had been started. This happens also with different backends and the driving interface (say, Idle with Tkinter...) Some solutions exist. The simplest one is the following. 1. Use a particular event source, e.g. launch: ani = anima.FuncAnimation(fig, proc, repeat=False, frames=sourcegen) where def sourcegen(): while running: yield 0 #or whatever return Include a button def astop(ev=None): global running running=False stopbutton.on_clicked(astop) and it will kill your animation in a proper way. Restarting it demands that "ani" be recreated within a callback, say, a startbutton. But this is not pausing. Recreating the animation, recreating and starting a timer, connecting all the callbacks... this takes time, and you SEE it. if you go down the road of implementing a full-blown event loop for matplotlib, is how well it will play with existing event loops. Whenever an interactive GUI backend is running, there's already an event loop at work: that of the GUI toolkit. Integrating multiple event loops in the same process takes some delicate footwork if you don't want to end up with a nasty fight between the two. Absolutely. But first, you don't need to launch show() and force some mainloop(), MainLoop(), gtk.main(), etc. under the hood. We wrote some loops under wx, simple-minded ; there is one included in the standard docs-and-demos. I don't know yet how to force WindowUpdate from Matplotlib, but some "plugin" solution should exist, since Matplotlib does that already. Second, even if an event loop runs already, the question is to plug in the access to the concrete event queue mechanism, not to superpose another one, and yell with horror at which level declare callbacks... Thank you, Fernando. Jerzy Karczmarczuk -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
I believe that I should terminate this thread (from my side), since the image is clear. The actual version of Matplotlib is not adapted to my needs, a rather involved animation of many objects, and changing. The last dialogue with Benjamin Root, whom I am deeply grateful, cleared my doubts. Ben confirms that I am on my own: > // you need to create your web of callbacks accordingly. The callback > registry is just simply a tool that we created for our use. Keep in > mind that your original question to this thread was "how do I fire > events?". I answered that question a while back. My question - sorry for being unclear - was how to fire events ASYNCHRONOUSLY. How to post them, to be processed by the event loop, not how to call callbacks. > Ok, but the callback registry is not an event loop. It is just a > callback registry. The main-loops are in the respective GUI toolkits. I know that. I read a good part of the matlotlib source, but not all of this, since I thought that asking questions might be more efficient. And actually it was. > There is no event queue in the CallbackRegistry. What we have done > in the respective GUI backends is to link various GUI actions to calls > to process(). The CallbackRegistry itself is GUI-neutral and heck, it > doesn't even assume a GUI exists, which allows for us to still use the > callback registry for other uses in non-interactive modes and headless > modes. Therefore, there is no mainloop, there is no event queue. This, I believe, is the final answer. Sigh. OK. I am not saved from the Pooh syndrome (The more he looked inside the more Piglet wasn't there), since now I plan to either code something myself, or to give it as a project to my students. I believe that Matplotlib merits this, there is plenty of potentialities, but the animation seems to be still in statu nascendi. > I also noticed that in the example you posted, you created your own > callback registry. Why didn't you use the existing one that comes > with the figure canvas? > Oh, of course. But this was accidental, it doesn't change anything. > Quite honestly, I (and I suspect others) are not sure what you are > asking of us. You seem to be quite knowledgeable, but -- quite > frankly -- all I see is you complaining about the problem. /.../ I > need you to be very clear about what you want and to exclude any > extraneous "rants" you may have. NO SIR. I am not complaining (cite my "complaints" if you disagree). I am trying to find a solution to a problem of delayed, asynchronous event processing within Matplotlib. I try to be compact, this is just a mailing list. And please: what "rants"??? I would never say anything bad about the system nor its authors, I am asking questions. No bugs to reports (only that from time to time Python declares some execution error of a sub-process, but it may have several sources). > My only guess is that you were hoping that there was a GUI-neutral > mainloop in mpl. I am sorry to say that one doesn't exist in the > manner you are speaking. Again, this IS the answer. Thank you very much. There is one "rant", if you wish (of course, I am joking). The animation objects (FuncAnimation, etc.) are coded as they are, probably sufficient for you. They are "one shot". But if you want to stop and to resume your animation, they are not so well adapted. Calling ._stop (not documented) from a callback is deadly, because of the cleaning procedures. You can't re-_start it. The only way - as I see it - is to create another animation. OK, but this might not be the most efficient way to do it. I am afraid that my fascination by Matplotlib, which I really use for my teaching of scientific programming and visualization, pushed me to try to use the package outside its actual limits. Sorry bor bothering you. If I find something of general interest, I will post it, perhaps. All the best, sincerely. Jerzy Karczmarczuk Caen, France -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
Benjamin Root about my miserable event problem : Still not sure why my suggestion would not work: http://matplotlib.sourceforge.net/api/cbook_api.html#matplotlib.cbook.CallbackRegistry I thought I told you. Probably I am doing something utterly false, but my distilled problem is that*I am generating events from within a callback*. Here you are a complete skeleton program. from pylab import * from matplotlib.cbook import * from matplotlib.widgets import Button fig=figure() ax = fig.add_subplot(1,1,1) xis=axis([0,1,0,1]) subplots_adjust(left=0.1, bottom=0.1) clrax = axes([0.67, 0.02, 0.08, 0.04]) clbut = Button(clrax, 'Clear', color="1.0") goax = axes([0.88, 0.02, 0.08, 0.04]) gobut = Button(goax, 'Go', color="#40ffa0") cbacks = CallbackRegistry() def line(*evt): plot(rand(2),rand(2)) ; draw() cbacks.process('line_', None) linv = cbacks.connect('line_', line) def clr(ev=None): del ax.lines[:] clbut.on_clicked(clr) def start(evt): cbacks.process('line_', None) gobut.on_clicked(start) subplot(1,1,1) show() The function line() is the main iterative engine, a "loop" without looping. It should post an event which re-launches it, and still leaving the master loop active, so I can clear the figure. Nope. This is a /*recursive call*/. Python bombs after a while, recursive limit exceeded, and only then the Clear button wakes up. Thank you for your effort. Jerzy -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
Tony Yu suggests that my multiple and changing animation problems could be solved using coroutining. > have you looked into using a coroutine. /... /I've attached a simple > example below. > > import matplotlib.pyplot as plt > import numpy as np > def datalistener(): > ... > while True: > y0 = yield > x = np.hstack((line.get_xdata(), i)) > ... > plt.ion() > ... Thank you Tony. No, unfortunately this is again a "side solution". Of course, coroutines, or just a simple event loop using Python generators without .send(), are perfectly decent tools to simulate parallel "movements". But, coroutines as such, are better adapted to situations where the actors transfer the control among themselves, where there is a network of direct communications, a "multi-ping-pong". In my case this is redundant, my "planets" which move concurrently are independent, and they, after having updated their properties, need only to yield the control to the interface, to draw them. The interface resumes (by calling, no .send() is needed) all the actors in sequence. I repeat again : I COULD have written my own event loop (under ion()). But I don't want to do this, since show() which calls some lower level mainloop() does all this already! In particular, it handles the physical events, all mousing, which need anyway some lower-level mechanisms, and my own coroutines won't help. I MUST use the built-in tools in order to handle the mouse. So, I repeat, my only [as I see it] rational choice is to plug-in my events into the standard loop. Under, say, plain wxPython, I can write my own, and call ProcessPendingEvents(), but with Matplotlib, no idea. Ben Root suggested to look some existing codes, say the Picker. But this is called upon a physical event, which is "fired" under the hood. My events are "virtual", I have to post them myself from a callback, so it canot call recursively another callback, or I am dead. Best regards. Jerzy -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Events
Benjamin Root answers my query concerning user-generated events : > To answer your question, take a look at how pick_event() is declared > in backend_bases.py: > > def pick_event(self, mouseevent, artist, **kwargs): > ... > self.callbacks.process(s, event) > > The function that "fires" the event is "self.callbacks.process(s, > event)", where "self" is the figure canvas. Dear Ben, thank you, but this is not exactly my problem. I don't want to call the callback myself, since the event should be "fired" from within a callback. I should have been more precise. Let's distil the problem. [This is a part of my current teaching...] I did already what you suggest here... Imagine an animation, which consists in generating a trajectory, segment after segment (say, of a planet). Classically this is a loop, but when it runs, the rest of the program is blocked. So, instead, the code behaves as a Python generator, generates just one segment, and that's all. But it "yields" something, it posts an event, put it in a queue, and somebody else, the mainloop() or similar, pops it off the queue and re-launches the callback. (With generators, it calls the .next()). No timers, as in Timer or Funct animations... It must be "decentralized", no recursive calls. My callback from time to time creates another planet, or destroys an existent, and there are simultaneous trajectories on the screen, several concurrent events in the queue. And the system should remain reactive, interpret buttons, sliders, etc. I know how to do this by hand, how to write my own event loop, declare a queue, and how to add to my private "virtual" event handling also the callbacks of mouse events. But this is an overkill, I repeat the functionalities which are already there, the event queue in particular. I did it with wx. But Matplotlib protects the user from the concrete back-end, and I want to protect my students as well, so I look for a "GUI-neutral" solution. Thanks. Jerzy -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Events
Does anybody know how to generate and process my "private" events? I can subclass the Event() class, say, MyEvent, with a name "my_event", and I can - canvas.mpl_connect('my_event', aCallback) but then, how to fire one? (I don't want to call the callback directly). Suppose that the interface, when show() is active launches a simulation/visualisation program which animates many things in its figure. From time to time something "special" appears, and its behaviour should be steered by those private events. (Yes, I know that I can do it in several other ways, or write my own event-processing loop, or use directly wxPython or PyGTK instead of Matplotlib. So, I don't need the replacement solution, but just a way to fire events within Matplotlib...) Thank you. Jerzy Karczmarczuk Caen, France -- Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users