All Questions
Tagged with plot matplotlib
7,950 questions
770
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?
568
votes
13
answers
925k
views
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 ...
319
votes
21
answers
374k
views
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 ...
267
votes
1
answer
725k
views
How to set xlim and ylim for a subplot [duplicate]
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:
...
252
votes
10
answers
370k
views
Format y axis as percent
I have an existing plot that was created with pandas like this:
df['myvar'].plot(kind='bar')
The y axis is format as float and I want to change the y axis to percentages. All of the solutions I ...
250
votes
5
answers
705k
views
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 = ...
247
votes
10
answers
294k
views
Plotting in a non-blocking way with Matplotlib
I am having problems trying to make matplotlib plot a function without blocking execution.
I have tried using show(block=False) as some people suggest, but all I get is a frozen window. If I simply ...
214
votes
8
answers
263k
views
How do I tell matplotlib that I am done with a plot?
The following code plots to two PostScript (.ps) files, but the second one contains both lines.
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
plt.subplot(111)
x = [...
214
votes
6
answers
600k
views
How do I create a second (new) plot, then later plot on the old one?
I want to plot data, then create a new figure and plot data2, and finally come back to the original plot and plot data3, kinda like this:
import numpy as np
import matplotlib as plt
x = arange(5)
y =...
214
votes
1
answer
114k
views
What is the difference between pylab and pyplot? [duplicate]
What is the difference between
matplotlib.pyplot and matplotlib.pylab?
Which is preferred for what usage?
I am a little confused, because it seems like independent from which I import, I can do the ...
198
votes
7
answers
268k
views
matplotlib get ylim values
I'm using matplotlib to plot data (using plot and errorbar functions) from Python. I have to plot a set of totally separate and independent plots, and then adjust their ylim values so they can be ...
194
votes
2
answers
240k
views
How to export plots from matplotlib with transparent background?
I am using matplotlib to make some graphs and unfortunately I cannot export them without the white background.
In other words, when I export a plot like this and position it on top of another image, ...
189
votes
3
answers
636k
views
Plotting a list of (x, y) coordinates
I have a list of pairs (a, b) that I would like to plot with matplotlib in python as actual x-y coordinates. Currently, it is making two plots, where the index of the list gives the x-coordinate, and ...
187
votes
8
answers
425k
views
Plot smooth line with PyPlot
I've got the following simple script that plots a graph:
import matplotlib.pyplot as plt
import numpy as np
T = np.array([6, 7, 8, 9, 10, 11, 12])
power = np.array([1.53E+03, 5.92E+02, 2.04E+02, 7....
172
votes
3
answers
334k
views
Putting text in top left corner of matplotlib plot
How can I put text in the top left (or top right) corner of a matplotlib figure, e.g. where a top left legend would be, or on top of the plot but in the top left corner? E.g. if it's a plt.scatter(), ...