plot
How do I create a second (new) plot, then later plot on the old one?
If you find yourself doing things like this regularly it may be worth investigating the object-oriented interface to matplotlib. In your case: import matplotlib.pyplot as plt import numpy as np x = np.arange(5) y = np.exp(x) fig1, ax1 = plt.subplots() ax1.plot(x, y) ax1.set_title(“Axis 1 title”) ax1.set_xlabel(“X-label for axis 1”) z = np.sin(x) fig2, (ax2, ax3) … Read more
Plotting numerous disconnected line segments with different colors
use LineCollection: import numpy as np import pylab as pl from matplotlib import collections as mc lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]] c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]) lc = mc.LineCollection(lines, colors=c, linewidths=2) fig, ax = pl.subplots() ax.add_collection(lc) ax.autoscale() … Read more
Label data points on plot
How about print (x, y) at once. from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) A = -0.75, -0.25, 0, 0.25, 0.5, 0.75, 1.0 B = 0.73, 0.97, 1.0, 0.97, 0.88, 0.73, 0.54 ax.plot(A,B) for xy in zip(A, B): # <– ax.annotate(‘(%s, %s)’ % xy, xy=xy, textcoords=”data”) # <– ax.grid() plt.show()
How to display only a left and bottom box border in matplotlib?
Just set the spines (and/or ticks) to be invisible. E.g. import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.spines[‘right’].set_visible(False) ax.spines[‘top’].set_visible(False) plt.show() If you want to hide the ticks on the top and left as well, just do: ax.xaxis.set_ticks_position(‘bottom’) ax.yaxis.set_ticks_position(‘left’)
Set the legend location of a pandas plot
Well, Simply chain it. dframe.rank(ascending=False).plot(kind= ‘bar’).legend(loc=”best”) Assuming ‘dframe’ is a DataFrame.
How to make the angles in a polar plot go clockwise with 0° at the top
Updating this question, in Matplotlib 1.1, there are now two methods in PolarAxes for setting the theta direction (CW/CCW) and location for theta=0. Check out http://matplotlib.sourceforge.net/devel/add_new_projection.html#matplotlib.projections.polar.PolarAxes Specifically, see set_theta_direction() and set_theta_offset(). Lots of people attempting to do compass-like plots it seems.
How to change spacing between ticks
The spacing between ticklabels is exclusively determined by the space between ticks on the axes. Therefore the only way to obtain more space between given ticklabels is to make the axes larger. In order to determine the space needed for the labels not to overlap, one may find out the largest label and multiply its … Read more