Questions tagged [matplotlib]

Matplotlib is a plotting library for Python which may be used interactively or embedded in stand-alone GUIs. Its compact "pyplot" interface is similar to the plotting functions of MATLAB®.

Matplotlib is a comprehensive plotting and visualization library for the Python programming language and its NumPy numerical mathematics extension. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like tkinter, wxPython, Qt, or GTK, Jupyter and IPython notebooks.

There is also a procedural "pyplot" interface based on a state machine (like OpenGL), designed to closely resemble that of MATLAB.

Matplotlib can output PNG, PDF, PS, EPS, TIFF, JPEG, PGF, and SVG files, or plot in windows using a variety of toolkits (including plot animation).

Latest release information on Matplotlib's site.

Resources to get started:

71303 questions
3161
votes
14 answers

How do I change the size of figures drawn with Matplotlib?

How do I change the size of figure drawn with Matplotlib?
tatwright
  • 37,567
  • 6
  • 21
  • 9
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
1574
votes
18 answers

How to put the legend outside the plot

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets reduced. I want to keep the legend box outside…
pottigopi
  • 15,759
  • 3
  • 15
  • 4
944
votes
11 answers

How to make IPython notebook matplotlib plot inline

I am trying to use IPython notebook on MacOS X with Python 2.7.2 and IPython 1.1.0. I cannot get matplotlib graphics to show up inline. import matplotlib import numpy as np import matplotlib.pyplot as plt %matplotlib inline I have also tried…
Ian Fiske
  • 10,482
  • 3
  • 21
  • 20
908
votes
12 answers

Purpose of "%matplotlib inline"

What exactly is the use of %matplotlib inline?
Rishabh
  • 9,367
  • 4
  • 11
  • 6
890
votes
16 answers

How to change the font size on a matplotlib plot

How does one change the font size for all elements (ticks, labels, title) on a matplotlib plot? I know how to change the tick label sizes, this is done with: import matplotlib matplotlib.rc('xtick', labelsize=20) matplotlib.rc('ytick',…
Herman Schaaf
  • 46,821
  • 21
  • 100
  • 139
881
votes
12 answers

How do I set the figure title and axes labels font size?

I am creating a figure in Matplotlib like this: from matplotlib import pyplot as plt fig = plt.figure() plt.plot(data) fig.suptitle('test title') plt.xlabel('xlabel') plt.ylabel('ylabel') fig.savefig('test.jpg') I want to specify font sizes for…
vasek1
  • 13,541
  • 11
  • 32
  • 36
753
votes
14 answers

Changing the tick frequency on the x or y axis

I am trying to fix how python plots my data. Say: x = [0, 5, 9, 10, 15] y = [0, 1, 2, 3, 4] matplotlib.pyplot.plot(x, y) matplotlib.pyplot.show() The x axis' ticks are plotted in intervals of 5. Is there a way to make it show intervals of 1?
Dax Feliz
  • 12,220
  • 8
  • 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
652
votes
9 answers

How to set the axis limits

I need help with setting the limits of y-axis on matplotlib. Here is the code that I tried, unsuccessfully. import matplotlib.pyplot as plt plt.figure(1, figsize = (8.5,11)) plt.suptitle('plot title') ax = [] aPlot = plt.subplot(321, axisbg = 'w',…
Curious2learn
  • 31,692
  • 43
  • 108
  • 125
632
votes
6 answers

How do I change the figure size with subplots?

How do I increase the figure size for this figure? This does nothing: f.figsize(15, 15) Example code from the link: import matplotlib.pyplot as plt import numpy as np # Simple data to display in various forms x = np.linspace(0, 2 * np.pi, 400) y =…
Brian
  • 13,996
  • 19
  • 70
  • 94
623
votes
7 answers

pyplot scatter plot marker size

In the pyplot document for scatter plot: matplotlib.pyplot.scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, faceted=True,…
LWZ
  • 11,670
  • 22
  • 61
  • 79
584
votes
7 answers

What does the argument mean in fig.add_subplot(111)?

Sometimes I come across code such as this: import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 25] fig = plt.figure() fig.add_subplot(111) plt.scatter(x, y) plt.show() Which produces: I've been reading the documentation like…
pleasedontbelong
  • 19,542
  • 12
  • 53
  • 77
563
votes
6 answers

Plot logarithmic axes

I want to plot a graph with one logarithmic axis using matplotlib. I've been reading the docs, but can't figure out the syntax. I know that it's probably something simple like 'scale=linear' in the plot arguments, but I can't seem to get it…
Jim
548
votes
13 answers

Rotate axis tick labels

I can't figure out how to rotate the text on the X Axis. Its a time stamp, so as the number of samples increase, they get closer and closer until they overlap. I'd like to rotate the text 90 degrees so as the samples get closer together, they…
tMC
  • 18,105
  • 14
  • 62
  • 98
1
2 3
99 100