72,835 questions
3265
votes
16
answers
6.4m
views
How do I change the size of figures drawn with Matplotlib?
How do I change the size of figure drawn with Matplotlib?
1801
votes
25
answers
3.2m
views
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)?
1723
votes
18
answers
2.1m
views
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 ...
969
votes
12
answers
1.1m
views
Purpose of "%matplotlib inline"
What exactly is the use of %matplotlib inline?
956
votes
11
answers
1.4m
views
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 ...
933
votes
17
answers
2.3m
views
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',...
932
votes
12
answers
2.6m
views
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(...
794
votes
15
answers
1.9m
views
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 ...
772
votes
4
answers
1.2m
views
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?
733
votes
10
answers
2.0m
views
How to set the axis limits in Matplotlib?
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')...
690
votes
6
answers
1.8m
views
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 ...
668
votes
7
answers
2.0m
views
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,
...
657
votes
13
answers
1.4m
views
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 ...
613
votes
7
answers
1.6m
views
Plot logarithmic axes
I want to plot a graph with one logarithmic axis using matplotlib.
Sample program:
import matplotlib.pyplot as plt
a = [pow(10, i) for i in range(10)] # exponential
fig = plt.figure()
ax = fig....
605
votes
8
answers
560k
views
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 ...