| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
Search - Search the Web, Wikipedia, Dictionary and More... medilexicon.com | The Wikipedia Project nigeriaphysio.org | SAPHO Syndrome Wikipedia - Orthopedics, Orthopedic Surgery & Orthopedic... orthopaedicweblinks.com | wrangler Discount wheelchairs, chairs la wikipedia wheel chair electropedicbeds.com |
Graphs and other pictures can contribute substantially to an article. Here are some hints on how to create a graph. The source code for each of the example images on this page can be accessed by clicking the image to go to the image description page. Main article: Wikipedia:Graphs
[edit] Guidelines
See also the graphics tutorials on how to create pictures, and the picture tutorial on how to include them in articles. There is additional discussion of plotting on Template talk:Probability distribution#Standard_Plots. [edit] Plotting[edit] gnuplotFurther information: gnuplot
Many of the graphs on Wikipedia were made with the free software program gnuplot. It can be used by itself or in conjunction with other software. For example, to plot the data in file "data": set xlabel "steps" set ylabel "result" unset key #use bars in plot: with boxes #choose line color/style in plot: linetype n #plot filled bars (fs): pattern n set style fill pattern 2 plot "data" with boxes linetype 3 fs [edit] SVG A plot of Hermite polynomials, generated by gnuplot in SVG format A plot of the floor function, generated by gnuplot in SVG format Now that Mediawiki supports SVG, it's usually best to generate SVG images directly. SVG images have many advantages, like being fully resizable, easier to modify, and so on, though they are sometimes inferior to raster images. Decide on a case-by-case basis. A typical plt file could start with: set terminal svg enhanced size 1000 1000 fname "Times" fsize 36 set output "filename.svg"
[edit] Raster A plot of the normal distribution, generated by gnuplot Gnuplot can also generate raster images (PNG): For the best results, a PostScript file should be generated and converted into PNG in an external program, like the GIMP. PostScript is generated with the line set terminal postscript enhanced: set terminal postscript enhanced color solid lw 2 "Times-Roman" 20 set output "filename.ps"
You should use a large number of samples for high-quality plots: set samples 1001 This is important to prevent aliasing or jagged linear interpolation (see Image:Exponentialchirp.png and its history for an example of aliasing). Labels are helpful, but remember to keep language-specific information in the caption if it's not too inconvenient. Including the source code and/or an image without text helps other users create versions in their own language, if text is included in the image. set xlabel "Time (s)" set ylabel "Amplitude" The legend or key is positioned according to the coordinate system you used for the graph itself: set key 4,0 Most other options are not Wikipedia-graph-specific, and should be gleaned from documentation or the source code included with other plots. An example of a plot generated with gnuplot is shown on the right, with source code on the image description page. [edit] Maxima A plot of the Hilbert transform of a square wave, generated by gnuplot from Maxima Maxima is a computer algebra system licensed under the GPL, similar to Mathematica or Maple. It uses gnuplot as its default plotter, though others are available, such as openmath. Plotting directly to PostScript from Maxima is supported, but gnuplot's PostScript output is more powerful. The most-used commands are plot2d and plot3d: plot2d (sin(x), [x, 0, 2*%pi], [nticks, 500]); plot3d (x^2-y^2, [x, -2, 2], [y, -2, 2], [grid, 12, 12]); Since the plot is sent to gnuplot as a series of samples, not as a function, the Maxima nticks option is used to set the number of sampling points instead of gnuplot's set samples. Additional plot options are included in brackets inside the plot command. To use the same options as in the above gnuplot example, add these lines to the end of the plot command: PostScript output: [gnuplot_term, ps] [gnuplot_ps_term_command, "set term postscript enhanced color solid lw 2 'Times-Roman' 20"] SVG output: [gnuplot_term, ps] [gnuplot_ps_term_command, "set terminal svg enhanced size 1000 1000 fname 'Times' fsize 36"] Output filename: [gnuplot_out_file, "filename.ps"] Additional gnuplot commands: [gnuplot_preamble, "set xlabel 'Time (s)'; set ylabel 'Amplitude'; set key 4,0"] Like so: plot2d (sin(x), [x, 0, 2*%pi], [nticks, 500], [gnuplot_term, ps], [gnuplot_ps_term_command, "set term postscript enhanced color solid lw 2 'Times-Roman' 20"], [gnuplot_out_file, "filename.ps"], [gnuplot_preamble, "set xlabel 'Time (s)'; set ylabel 'Amplitude'; set key 4,0"]); Similar for svg output: plot2d (sin(x), [x, 0, 2*%pi], [nticks, 500], [gnuplot_term, ps], [gnuplot_ps_term_command, "set terminal svg enhanced size 1000 1000 fname 'Times' fsize 36"], [gnuplot_out_file, "filename.svg"]); Note that the font and labels are in single quotes now, nested inside double quotes. Multiple commands are separated by semicolons. An example of a plot generated with gnuplot in Maxima is shown on the right, with source code on the image description page. [edit] GNU OctaveGNU Octave is a numerical computation program; effectively a MATLAB clone. It uses gnuplot extensively (though also offers interfaces to Grace and other graphing software). The commands are plot (2D) and splot (surface plot), or gplot and gsplot ("almost exactly" the same). gnuplot settings are accessed with the gset command: t = [0 : .01 : 1]; y = sin (2*pi*t); gset terminal postscript enhanced color solid lw 2 "Times-Roman" 20 gset output "filename.ps" gset xlabel "Time (s)" gset ylabel "Amplitude" gset key 4,0 plot (t,y) If x functions are plotted, separated by commas, they will all appear on page x of the resulting .ps file. Octave uses Gnuplot for plotting, which generates SVG output that triggers a bug in Inkscape. The issue can be corrected with a simple Perl script [edit] MatplotlibMatplotlib is a plotting package for the free programming language Python. Its pylab interface is procedural and modeled after MATLAB, while the full Matplotlib interface is object-oriented. Python and Matplotlib are cross-platform, and are therefore available for Windows, OS X, and the Unix-like operating systems like Linux and FreeBSD. Matplotlib can create plots in a variety of output formats, such as PNG and SVG. (Numerous examples with Python source code are available at http://matplotlib.sourceforge.net/gallery.html) Matplotlib mainly does 2-D plots (such as line, contour, bar, scatter, etc.), but 3-D functionality is also available in some releases. Here is a simple line plot in pylab (output image is shown on the right): from pylab import * # import the Pylab module x = [1,2,3,4] # list of x values y1 = [8,3,5,6] # list of y values y2 = [1,6,4,6] # another list of y values plot(x, y1, 'o-') # do a line plot of data plot(x, y2, 's--') # plot the other data with a dashed line xlabel("foo") # add axis labels ylabel("bar") # xticks(x) # set x axis ticks to x values title("Pylab Demo") # set plot title grid(True, ls = '-', c = '#a0a0a0') # turn on grid lines savefig("pylab_example.svg") # save as SVG show() # show plot in GUI (optional) Save this script as e.g. pylab_demo.py and then run it with python pylab_demo.py. After a few seconds, a window with the interactive graphical output should pop up. [edit] GeoGebra GeoGebra can be used to plot curves and points, as well as experiment with and draw geometric shapes. It also exports to SVG. GeoGebra is a dynamic geometry program that can be used to create geometric objects free-hand using compass-and-ruler tools. It can also plot points and algabraic or parametric curves. It supports SVG, PNG, EPS, PDF, EMF, PGF/TikZ and PSTricks as export formats (though the image layout and style controls are still preliminary), and has support for LaTeX formulas within text objects. [edit] XfigXfig is an open source vector graphics editor that runs under X on most Unix platforms. In xfig, figures may be drawn using objects such as circles, boxes, lines, spline curves, text, etc. It is possible to import images in many formats, such as GIF, JPEG, SVG, and EPSF. [edit] RThe free statistical package R (see R programming language) can make a wide variety of nice-looking graphics. It is especially effective to display statistical data. On Wikimedia Commons, the category Created with R contains many examples, often including the corresponding R source code. Other examples can be found in the R Graph Gallery. In order to output postscript, use “postscript” command: postscript(file = "myplot.ps") plot(...) graphics.off() The last command will close the postscript file; it won't be ready until it's closed. With an additional (free) package, it's also possible to generate SVG-graphs with R directly. See an example with code on Image:Circle area Monte Carlo integration2.svg. Other packages (lattice, ggplot2) provide alternative graphics facilities or syntax. Here is another example with data. [edit] DiagramsFor graph-theory diagrams and other "circles-and-arrows" pictures, Graphviz is quick and easy, and also able to make SVGs. A rendering of several three-dimensional surfaces done using the ray-tracer, POV-Ray. [edit] SurfacesPOV-Ray is a general-purpose ray-tracing package with a scene description language very similar to many programming languages. It can render parametric surfaces and algebraic surfaces of degree up to seven, as well as approximations of parametric surfaces using triangle meshes via the third-party include file, "param.inc". An updated version of the file "screen.inc" can be used to output the exact two-dimensional screen coordinates of any three-dimensional object. Other usable tools include:
Illustration of Desargues' theorem made using Inkscape [edit] InkscapeNext to being useful for post-processing (see the next section), Inkscape is a point-and-click tool that can be used to create high-quality figures. It is a particularly easy tool for creating vector graphics. [edit] GriThe Gri graphical language can be used to generate figures using a script-like plotting commands. Unlike other tools Gri is not point and click, and requires learning the Gri script syntax. [edit] Post-processing[edit] Modifying SVG imagesSVG images can be post-processed in Inkscape. Line styles and colors can be changed with the Fill and Stroke tool. Objects can be moved in front of other objects with the Object→Raise and Lower menu commands. Saving from Inkscape also adds information that isn't present in Gnuplot's default output – neither Firefox nor Mozilla will render the file natively without it. These browsers can be persuaded to render Gnuplot's SVG output if the [edit] Converting PostScript to SVGPostScript can be converted to SVG with pstoedit (it works both on Linux and Microsoft Windows). On Linux, this tool can be invoked for example as
Direct SVG output is probably better if the program supports it. See Wikipedia:WikiProject Electronics/How to draw SVG circuits using Xcircuit for an example. [edit] Editing PostScript colors and linestyles manuallySetting colors and linestyles in gnuplot is not easy. They can more easily be changed after the PostScript file is generated by editing the PostScript file itself in a regular text editor. This avoids needing to open in proprietary software, and really isn't that difficult (especially if you are unfamiliar with other PS editing software). Find the section of the .ps file with several lines starting with /LT. Identify the lines easily by their color ("the arrow is currently magenta and I want it to be black. Ah, there is the entry with 1 0 1, red + blue = magenta") or by using the gnuplot linestyle−1 (for instance, gnuplot's linestyle 3 corresponds to the ps file's /LT2). Then you can edit the colors and dashes by hand. /LT0 { PL [] 1 0 0 DL } def
/LT2 { PL [2 dl 3 dl] 0 0 1 DL } def
/LT5 { PL [5 dl 2 dl 1 dl 2 dl] 0.5 0.5 0.5 DL } def
/LTb is the graph's border, and /LTa is for the zero axes. [edit] Converting PostScript to PNG and editing with the GIMPTo post-process PostScript files for raster output (vector is preferred): [edit] Manual conversion
[edit] Command-line methodAnother route to convert a PS or EPS file (postscript) in png is to use ImageMagick, available on many operating systems. A single command is needed: convert -density 300 file.ps file.png The density parameter is the output resolution, expressed in dots per inch. With the standard 5x3.5in size of a gnuplot graph, this results in a 1500x1050 pixels PNG image. ImageMagick automatically applies antialiasing, so no post-processing is needed, making this technique especially suited to batch processing. The following Makefile automatically compiles all gnuplot files in a directory to EPS figures, converts them to PNG and then clears the intermediate EPS files. It assumes that all gnuplot files have a ".plt" extension and that they produce an EPS file with the same name, and the ".eps" extension: GNUPLOT_FILES = $(wildcard *.plt) # create the target file list by substituting the extensions of the plt files FICHIERS_PNG = $(patsubst %.plt,%.png, $(GNUPLOT_FILES)) all: $(FICHIERS_PNG) %.eps: %.plt @ echo "compillation of "$< @gnuplot $< %.png: %.eps @echo "conversion in png format" @convert -density 300 $< $*.png @echo "end" [edit] See also |
| ↑ top of page ↑ | about thumbshots |