Questions tagged [plot]

The graphical representation of a mathematical function or a set of data. There are different kinds of plots, such as line plots, bar plots, or scatter plots.

Wikipedia uses the following definition of plot:

A plot is a graphical technique for presenting a data set drawn by hand or produced by a mechanical or electronic plotter. It is a graph depicting the relationship between two or more variables used, for instance, in visualising scientific data.

Plots help greatly in visualizing the structure of your data, or the outcome of an analysis. Good plots yield insight into the data, which is often hard to gain from just looking at the numbers.

roughly has three separate systems which provide plotting facilities:

  • Base plot: these are the plot routines standardly available in R. The syntax works roughly equivalent to MATLAB. The first one creates a plot, then additional calls to, for example, points or lines adds additional graphical features to the plot.
  • lattice: which provides an implementation of Trellis graphics (S-PLUS) for R.
  • ggplot2: a loose implementation of the grammar of graphics for R.

Different programming platforms support a variety of plot options. Noteworthy are Python's - a 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms, Matlab's and Mathematica's plot provides the starting point for 2-D line plots, and so forth.

Another widely used library is ; which is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. For a brief introduction to the ideas behind the library, you can read the introductory notes. Here are a few examples to see what you can do with seaborn.

An additional plotting library is . Gnuplot offers easy plotting that can be done through the command line interface. It works for Mac, Windows, Linux, and other operating systems. Gnuplot is very powerful because of the range of options when it comes to types of plots (2d, 3d, histogram, etc.) and the output formats (PNG, EPS, SVG, etc.). More info can be seen here.


Related tags

37452 questions
1680
votes
24 answers

Save plot to image file instead of displaying it

This displays the figure in a GUI: import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 4, 9]) plt.show() But how do I instead save the figure to a file (e.g. foo.png)?
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
761
votes
7 answers

How can we make xkcd style graphs?

Apparently, folk have figured out how to make xkcd style graphs in Mathematica and in LaTeX. Can we do it in R? Ggplot2-ers? A geom_xkcd and/or theme_xkcd? I guess in base graphics, par(xkcd=TRUE)? How do I do it? As a first stab (and as much more…
jebyrnes
  • 9,082
  • 5
  • 30
  • 33
733
votes
3 answers

When to use cla(), clf() or close() for clearing a plot

Matplotlib offers these functions: cla() # Clear axis clf() # Clear figure close() # Close a figure window When should I use each function and what exactly does it do?
southoz
  • 7,351
  • 3
  • 15
  • 5
681
votes
17 answers

Plot two graphs in a same plot

I would like to plot y1 and y2 in the same plot. x <- seq(-2, 2, 0.05) y1 <- pnorm(x) y2 <- pnorm(x, 1, 1) plot(x, y1, type = "l", col = "red") plot(x, y2, type = "l", col = "green") But when I do it like this, they are not plotted in the same…
Sandra Schlichting
  • 25,050
  • 33
  • 110
  • 162
535
votes
10 answers

Hiding axis text in matplotlib plots

I'm trying to plot a figure without tickmarks or numbers on either of the axes (I use axes in the traditional sense, not the matplotlib nomenclature!). An issue I have come across is where matplotlib adjusts the x(y)ticklabels by subtracting a value…
Dave
  • 6,184
  • 8
  • 26
  • 28
498
votes
14 answers

How to change legend title in ggplot

I have the following plot like below. It was created with this command: library(ggplot2) df <- data.frame(cond = factor(rep(c("A", "B"), each = 200)), rating = c(rnorm(200), rnorm(200, mean=.8))) ggplot(df, aes(x=rating,…
neversaint
  • 60,904
  • 137
  • 310
  • 477
431
votes
2 answers

How to set limits for axes in ggplot2 R plots?

I plot the following: library(ggplot2) carrots <- data.frame(length = rnorm(500000, 10000, 10000)) cukes <- data.frame(length = rnorm(50000, 10000, 20000)) carrots$veg <- 'carrot' cukes$veg <- 'cuke' vegLengths <- rbind(carrots,…
David B
  • 29,258
  • 50
  • 133
  • 186
356
votes
13 answers

Plot two histograms on single chart with matplotlib

I created a histogram plot using data from a file and no problem. Now I wanted to superpose data from another file in the same histogram, so I do something like this n,bins,patchs = ax.hist(mydata1,100) n,bins,patchs = ax.hist(mydata2,100) but the…
Open the way
  • 26,225
  • 51
  • 142
  • 196
346
votes
11 answers

How to save a plot as image on the disk?

I plot a simple linear regression using R. I would like to save that image as PNG or JPEG, is it possible to do it automatically? (via code) There are two different questions: First, I am already looking at the plot on my monitor and I would like to…
blakc05
  • 3,629
  • 4
  • 16
  • 6
308
votes
21 answers

Is there a way to detach matplotlib plots so that the computation can continue?

After these instructions in the Python interpreter one gets a window with a plot: from matplotlib.pyplot import * plot([1,2,3]) show() # other code Unfortunately, I don't know how to continue to interactively explore the figure created by show()…
meteore
  • 4,635
  • 2
  • 22
  • 14
261
votes
9 answers

How to plot two histograms together in R?

I am using R and I have two data frames: carrots and cucumbers. Each data frame has a single numeric column that lists the length of all measured carrots (total: 100k carrots) and cucumbers (total: 50k cucumbers). I wish to plot two histograms -…
David B
  • 29,258
  • 50
  • 133
  • 186
253
votes
1 answer

How to set xlim and ylim for a subplot

I would like to limit the X and Y axis in matplotlib for a specific subplot. The subplot figure itself doesn't have any axis property. I want for example to change only the limits for the second plot: import matplotlib.pyplot as…
Cupitor
  • 11,007
  • 19
  • 65
  • 91
251
votes
5 answers

Label axes on Seaborn Barplot

I'm trying to use my own labels for a Seaborn barplot with the following code: import pandas as pd import seaborn as sns fake = pd.DataFrame({'cat': ['red', 'green', 'blue'], 'val': [1, 2, 3]}) fig = sns.barplot(x = 'val', y = 'cat', …
Erin Shellman
  • 3,553
  • 4
  • 21
  • 26
238
votes
1 answer

Minimizing NExpectation for a custom distribution in Mathematica

This relates to an earlier question from back in June: Calculating expectation for a custom distribution in Mathematica I have a custom mixed distribution defined using a second custom distribution following along the lines discussed by @Sasha in a…
Jagra
  • 3,149
  • 1
  • 18
  • 19
237
votes
5 answers

How do I draw a grid onto a plot in Python?

I just finished writing code to make a plot using pylab in Python and now I would like to superimpose a grid of 10x10 onto the scatter plot. How do I do that? My current code is the following: x = numpy.arange(0, 1, 0.05) y = numpy.power(x, 2) fig…
LiamNeesonFan
  • 2,653
  • 5
  • 18
  • 13
1
2 3
99 100