Plot in veusz command line
You may be wondering why I used savefig in Line 25 instead of show. I’d rather not have the namespace polluted, but I’ll be damned if I’m going to type things like np.sin(x) every time I need a trig function.
I’m assuming that if I screw up the input, whatever error message Python spits back will help me fix it. The try/except clause isn’t really error handling, it’s just a simple way to handle optional arguments. If you want to connect the points with a line, use the -l option: pbpaste | pplot -l > plot.pngĢ4: plt.grid(which='both', color='#aaaaaa')Ģ5: plt.savefig(sys.stdout, format='png')Ī few things about plot that I’m not proud of: The x and y values can be separated by tabs, spaces, or commas. On the Mac, it would be common to pass data in from the clipboard this way: pbpaste | pplotĪs with plot, pplot produces an 800×600 PNG image that’s sent to standard output, so one would normally redirect this to a file: pbpaste | pplot > plot.pngĮach line of the input data represents one (x, y) point. The script that plots lists of points, pplot, gets its data from standard input. No controls for tick marks or grid spacing are provided-this is quick and dirty plotting.
Normally, this would be redirected to a file, plot 'tan(x) x' pi 3*pi/2-.01 0 5 > plot.pngĪnd viewed in whatever graphics program the user prefers. The result of plot is an 800×600 PNG image that’s sent to standard output. This example also shows that you can use expressions in the limits.
Thus, something like plot 'tan(x) x' pi 3*pi/2-.01 0 5Ĭan be used to find the intersection of the two given functions. More than one function can be specified separate them with a semicolon. The function can include any Python expression or function, including those in the NumPy library. A common reason to specify the y limits is if the function “blows up” between the x limits and the extreme y values make the rest of the graph look flat. The last two arguments, the minimum and maximum y values are optional-if they aren’t given, the script will figure them out. Three arguments are required: the function itself, which would normally be enclosed in quotes to avoid problems with shell interpretation the minimum x value and the maximum x value. Functionsįor these, everything is given on the command line. The goal is to make readable graphs very quickly. The graphs produced aren’t intended to be of publication quality. The scripts require the NumPy and matplotlib modules. Two simple scripts for creating plots from the command line: one for plotting functions and the other for plotting points. The scripts are in this GitHub repository, and I’ll quote its README to explain how they’re used. So I wrote a couple of little scripts to make plots from the command line.
I don’t want my train of thought derailed by the context shift that comes with starting up a program and fiddling with it-I just want a reasonable-looking graph now. The problem with making graphs in Matplotlib, Gnuplot, and even Numbers, is that it takes too long to get something that looks halfway decent 1 when I’m not in “graph-making mode.” I’ll be working on a problem and realize that a quick visualization of a function or some data would help my understanding. Next post Previous post Simple plotting from the command line