Currently, I use print -dpng foo.png to print a plot to file in Octave 3.0.1 on Ubuntu.
Sometimes, I generate thousands of images in a loop.
Whenever a new image pops up, it grabs the mouse control precluding me from multitasking.
Is there anyway to print silently or quietly?
It would be easier to answer your question with a little more information about what you are doing. But with a little guessing maybe this is what you need:
f = figure
set(f, "visible", "off")
plot([1,2,3,4])
print("MyPNG.png", "-dpng")
Related
I'm trying to get some practice with C and C++ by playing with gnuplot, but whilst following an example on plotting a simple 2 column data file, I encountered an issue.
When I call gnuplot in my script, it refuses to open any window, and doesn't appear to do any work at all. I don't think this is an issue of window persistence, as I don't even see it open for a split second. I've tried fiddling with setting a persistent terminal and pausing after plotting to no avail. My CPU's activity meter never spikes as it does when I run my other example functions, leading me to believe it never opens in the first place.
However, the strangest part to me is that I managed to plot the data file with gnuplot just how I'd hoped to, but the only way I was able to get it to work was running gnuplot as a terminal command via system().
Below is my function I'm testing with. As the comments note, that system call seems to work perfectly, but I'd prefer to use gnuplot "regularly," not via system calls.
void ex2() {
Gnuplot gp("\"C:\\Program Files\\gnuplot\\bin\\gnuplot.exe\"");
// system("gnuplot -p -e \"plot '2col.dat'\""); #works for some reason?????
gp << "plot '2col.dat'\n";
std::cin.get();
}
I'd appreciate any help you can offer! I just want to be able to plot the file with the "gp <<" notation. I apologize if this is similar to another thread here, but every similar one I've found was solved by adding "pause mouse close" at the end or changing the terminal persist setting, which have not worked for me.
In Matlab I'm plotting a matrix (let's call it M) using imagesc over an image using imshow. I would like M to have a degree of transparency so I can actually see the image below. This is what I'm doing:
imshow(img); hold on;
h = imagesc(M);
set(h,'AlphaData',0.4); % set transparency to 40%
However, the last line generates an error when running it on Linux. I've been trying to solve it but nothing seems to work. I wonder if there is an alternative to the "AlphaData" property to make it transparent. Thanks!
EDIT: I'm using Matlab R2014a and Java 1.7 on a Linux CentOS 6.6
As Luis Mendo suggested, I just needed to change the renderer. You can:
>get(gcf,'renderer'); % to see which render engine is Matlab using
>set(gcf,'renderer'); % to get a list with all the possible renderers in your machine
So, at least in Linux, to change the renderer it's necessary to start Matlab from terminal by calling it as:
matlab -softwareopengl
Once this is done, setting transparency in an specific plot, as shown in the description of the question, is possible.
Is there any way to write a GUI under Ubuntu that one can work with gnuplot, octave and bash scripts together?
You'd have to make the GUI and call the scripts, be it octave, bash or gnuplot. You could probably make the plots in the GUI and forget octave. At the end I learned a little bit of ruby on rails to offer my fortran code on the cloud.
For example, You could use qt and call the octave function usino a system call. Or go web based and make an ajax call. There are just too many options, depending on which language/framework/libraries you use.
To make a script call from octave, see http://www.gnu.org/software/octave/doc/interpreter/Controlling-Subprocesses.html . There are many ways to do it. Depending on what you want, a mere
system("./my_script")
could do the job. If you need to get the response, there is info on that link. Otherwise, the script could put the output in a file that you could read later from octave.
If you want to get input in octave, so that you make something close to a very light weighted user interface, you could make a loop and inside ask for input. For example
while x>0
x = input("Enter an integer (0 for quiting), 5 for script")
if (x==5)
system("./my_script")
endif
endwhile
After reading almost all I found here and in google, I've not found a simple and direct solution/example about plotting x-y values in c++ (console app win32, the black one) in visual studio 2008. Based on this post, I should use MsChart controls, would anyone be willing please to share a simple example about this?
This post, and many others, talk about libraries that don't belong to visual studio (so they won't compile with the EXE, hence it won't be included as part of the resulting EXE) or having the graphic displayed with excel. I just want to get a simple x-y graphic (and line going through these points), not worried at all if it is the ugliest and simplest graphic in the whole world, but it must appear automatically after my code run (perhaps in a new window or perhaps inside the console?) AND if I run this EXE in another pc, thousands of kilometers away from my pc, the graphic will still appear after the code runs.
Am I asking something too complex? boring?? I hope I could get some answers/examples/solutions instead of this post being closed =) Thanks in advance!
#Koushik thanks again for your support! even though I'm getting the whole picture I need a clear example to get it right, so to voteup I'd like to test this simple example:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double f(const double &x) {
return (
sin(x)*exp(-x));
}
int main()
{
unsigned Nplot = 100;
double x_low = 0.0;
double x_high = 20.0;
double h = (x_high - x_low)/(double)Nplot;
for (unsigned i=0;i<=Nplot;i++)
{
double x = x_low + i*h;
cout << setw(20) << x <<
setw(20) << f(x) << endl;
}
system("pause>nul");
return 0;
}
this is a pretty basic code to generate a sin(x) function. If you copy/paste this in console application Win32 in VC++ 2008 (new project/Visual C++/Win32/console application Win32/empty project/), the data will appear in the screen:
Then, putting these values in Excel gives:
I want this, BUT the output window should appear after the values appear in the console, and more important, the code must not depend on excel or something else external to the visual C++. So, writing some additional code to draw this line and after compiling, both must appear/work in any computer, especially in those without VS or any libraries, just running the EXE in windows, that's all. So, is it possible? could you share a simple code example to draw this line (to add it to the above code)? thanks!
you can call gui application or rather any other app by using the system("appname");. include the stdlib.h header. what you can do is create your console app and prepare the data. store those data in a file, open the app which can read the data from the file and plot it.
The gui application will not be so difficult to write either, if your goal is to only plot the data.in console you really cant draw things. in turbo c++ we had this option because it was mainly created for dos.
Algorithm:
1) prepare the data say time along x axis and amplitude along y axis. store this in a file using your own format.eg: x-ais data y-axis data .
2).Prepare a gui app that can plot the graph. use CreateGraphics() methods of the form to draw lines i.e the axes and the data line. CreateGraphics::drawLine() and CreateGraphics::drawLines() should help your progress.
EDIT:
you can pass command line args to the GUI app. this argument could be the data file path
The simplest thing would be for your console application, after computing the data, to create a window on screen (yes, console applications are allowed to use GUI) and then handle WM_PAINT with BeginPaint/PolyLine/EndPaint, using some appropriate scaling that makes the data (1) rightside up and (2) fit to the window.
You won't have any grid lines or axis labels, just the plotted line, but that's the bare minimum and can easily be done without either using or recreating an entire graphing library.
For an example of how to add GUI to your program, try Raymond Chen's scratch program, C++ version. Quite a bit of code to create just one window, but lucky for you, the only thing you have to change is the PaintContent() function.
Using Polyline is almost as straightforward as you could ask for -- it accepts an array of datapoints.
If you really want to add gridlines and labels, more Polyline calls and the ExtTextOut function will do the trick, but soon after that you'll want CreatePen and SelectObject to give control over line colors and styles (dotted, dashed, etc). And pay attention to the order -- draw the bottom things first so that later calls can cover over the top.
On the other hand if a single executable is not a requirement, I suggest you ship a copy of Gnuplot (the pgnuplot executable is designed for invocation from another program). First use wgnuplot to tune your plot options, then pass them to pgnuplot along with your data. You'll get reasonable scaling, gridlines, and labels for free this way, as well as exporting the result into common formats such as PNG.
I've been trying to get to grips with RRDTool. Aside from the data acquisition and storage, I'm having trouble plotting anything at all.
Using it like this doesn't return anything, i.e. no png is created:
rrdtool graph graph.png --end now --start end-60 DEF:in=teams.rrd:in:AVERAGE LINE2:in#000000
The only way to get any output is to include something like GPRINT:
rrdtool graph graph.png --end now --start end-60 DEF:in=teams.rrd:in:AVERAGE LINE2:in#000000 GPRINT:in:AVERAGE:"%8.2lf %s Bytes"
But even then, the graph itself is empty, while the GPRINT prints the correct value. I've also tried my luck with plotting a constant value and using HRULE, to no avail. I've tried pretty much everything, manually specifying start and end as well as upper and lower limits.
This is on Debian Squeeze and Ubuntu 11.04.
Update:
Nevermind, I "solved" my problem. Turns out it had something to do with shell-expansion, and putting quotes around the "LINE:in:#000000" was sufficient. Stupid mistake.