Everything looks OK if I just run the scripts in Pycharm. It will show the plots.
However, after I convert the scripts into exe file. It can save the plots, but it won't show any plot. The most weird thing is that it will re-open another exe file.
Thanks, really appreciate if someone know the root cause.
As mentioned in the comment, calling matplotlib.use('WXAgg') is necessary, but there is another step: matplotlib has a backend object you need to import manually to paint a figure in wx: matplotlib.backends.backend_wxagg. This creates a figure canvas object inside a wx.panel of your choosing.
This answer contains a nice example. Furthermore, you can look up the actual object in matplotlib website, then proceed to look at their artist tutorial, which covers how to use matplotlib in applications rather well.
Related
I am unable to produce any charts in Python (matplotlib 3.5.1) with the pandas DataFrame plot() method. A window opens and the axes return value is <AxesSubplot:> as opposed to returning an object like that prints as somethig like <matplotlib.axes._subplots.AxesSubplot at 0x7f3958bcf9d0>, which is what I usually see when the plot works.
The backend is QtAgg and as far as I can tell from a poke between fora pages that report a similar problem this should be all right. This is also not a problem with needing to run matplotlib.pyplot.ion() as I see a window open, but it is black with no plot in it.
Any advice would be useful, thanks!
I have resolved the (mis)behaviour without really being sure that I have resolved the issue responsible for this misbehaviour.
As looked around for a way out, I found this discussion (How to change backends in matplotlib / Python) which made a lot of getting the back end setting right. Wondering if that would make a difference, I changed the back end. The QtAgg back end loaded by default from the matplotlibrc file and so following the instructions in the post on how to permanently change the back end, I modified the file so that the back end is now Qt5Agg. The data now plots.
I'm trying to compare different learning-rate-decays using Tensorflow. Therefore I visualize the cost functions in Tensorboard ('EVENTS'-tab). My problem is that the different plots of the functions are in very similar colors making it hard to compare them. Is there any possibility to change those colors?
Just create different summary writes with different log files for each learning rate. Then launch the tensorboard tool using:
tensorboard --logdir=tag1:/path/to/summary/one,tag2:/path/to/summary/two
There's currently no way to change those colors, but a recent release has made the colors more differentiated. Try updating and seeing if that helps.
This is very far from an actual solution, but in case someone only wants to change the colors for a screenshot in a paper or presentation its a quick workaround:
Open your browser dev tools (F12)
Search for the color code you want to change (the default orange is #ff7043) and replace it with the color you want
As suggested here, creating (and pointing tensorboard to) a symlink of a run's logdir is one workaround to change the color used to plot that run.
Is it possible to plot pandas objects inside the PTVS interactive debugger? Is it possible to save plots to disk as jpeg's?
I think I was able to do this when I first started using PTVS (last year, its awesome by the way!) but I just tried again and I dont get any plots appearing. I cant remember if I had to do something special to get this to work and from doing some google searches I get a confusing picture of the current best practice in this regard.
I want to be able to plot diagrams from my debug interactive window, similar to what is shown on this pandas tutorial.
http://pandas.pydata.org/pandas-docs/stable/visualization.html
Is this possible?
Visual Studio Professional 2013 update 4 (latest I think)
PTVS 2.1.21008.00 (latest I think)
All help is greatly appreciated.
-Jason
[edit: more info on this http://pytools.codeplex.com/discussions/574776 ]
Unfortunately not. The regular interactive has an IPython mode that, among other things, enables inline plots. But the Debug interactive doesn't have that.
You can, of course, still load matplotlib in the Debug interactive and tell it to plot things. But because there's no integration of event loops between it and VS in that mode, the plots will basically work like modal windows - you won't be able to continue debugging or otherwise interact with VS until you close the plot window.
For an analysis application I'm trying to:
Get a list of filenames from the user using PyQt4 QFileDialog
Extract some data from each file
Plot the aggregated data using pyplot
However, getting the filenames this way causes pyplot.show() to take a really, really long time. I've distilled the problem down to the following test case:
import matplotlib.pyplot as plt
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication(None)
fd = QtGui.QFileDialog(None)
filenames = fd.getOpenFileNames(caption='Select Data Files')
plt.plot([1,2,3,4,5])
plt.show()
Note that I'm not even doing anything with the filenames here--just getting them.
Selecting a single file from the dialog results in a plot time of 10 seconds. Interestingly, the time required for show() to complete goes up roughly linearly with the number of files selected. For 10 files it takes about 67 seconds for the plot to show.
This isn't a big deal for plotting data from a handful of files, but when aggregating data from Monte Carlo simulations where there are thousands of files it can take literally hours for the plot to show. Telling matplotlib to use the Qt4Agg backend results in the same behavior.
If I comment out the call to getOpenFileNames the script will complete in under a second.
I'm running the following versions of the relevant packages (should be latest):
Python 2.7
matplotlib 1.3.1
python-sip 4.13.2-1
python-qt4 4.9.1-2ubuntu1
python-sip-dev 4.13.2-1
python-qt4-dev 4.9.1-2ubuntu1
I uninstalled sip, qt4 and reinstalled them--same issue. I've seen the issue accross two separate machines--both running 32-bit Ubuntu 12.04.
Any help would be much appreciated--I've wasted an embarrassing amount of time waiting for plots to show.
Updates:
The type and name of the files selected doesn't seem to matter.
Cancelling or exiting the file dialog box results in no delay and an immediate plot.
Running the script as sudo eliminates the issue; however, the file dialog looks different when I run as sudo and may be using a different gui backend that doesn't conflict with pyplot's use of PyQt, so may be a red herring.
The program doesn't hang in getOpenFileNames, it hangs on the next call that uses PyQt. Whether that's a plot or another file dialog doesn't seem to matter--the first file dialog blocks both.
Calling app.processEvents() after running the dialog doesn't help.
Using PySide in place of PyQt4 results in the same behavior.
Using getOpenFileName instead of getOpenFileNames results in the same behavior.
Running getOpenFileNames with the DontUseNativeDialog option works (no delay)
None of the other QFileDialog options have any effect (ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, ReadOnly, HideNameFilterDetails, DontUseSheet)
What I am ultimately trying to do is to create a grid of images for print that are minor variations of the same thing (different text is all). Looking through online resources I was able to create a script that changes the text and exports all of the images necessary (several hundred). What I am trying to do now is to import all of these images into a new photoshop document and lay them all out in a grid and I can't seem to find any examples of this.
Can anyone point me in the right direction to place a file at a specific coordinate (I'm using CS5 and have the design suite so if there is a way in illustrator to do this quickly...)?
Also, I'm open to other ideas on how to do this (even other programs) easily. It's for labels so the positioning on the sheet has to be pretty precise...
The art layer object has a translate() method that takes delta x and y params. You'll need to open each image, copy it to the target document, get its current location (using artLayer.bounds) and do the math to find the deltas to position it where you want it. Your deltas can be in pixels so you'll get plenty of precision.
Check out your 'JavaScript Scripting Reference' pdf in your Adobe install directory for more details.
Ok I'm marking Anna's response as the answer because though I didn't fully test it, it seems like it should work and answers the original question with jsx. However I'm also leaving my final solution in case anyone else runs across this with the same issue and may prefer this method as well.
What I ended up doing instead is using InDesign. I figured out that it has a grid option that lets you import a number of files and place them all in an equal grid in a single command. This is almost exactly what I was looking for, except that it leaves a small border/margin in between the columns and grids and mine were designed to meet exactly.
I couldn't figure out how to make it not have the border (I have very little experience with InDesign, it may be possible). However I was able to select all my images and scale them uniformly to be the correct size, then I just selected each column and dragged it over to snap to the adjacent column and the same with rows...