How to plot a circle in Matlab?

Don’t laugh, but the easiest would be to use the rectangle function, indeed 😉 %// radius r = 2; %// center c = [3 3]; pos = [c-r 2*r 2*r]; rectangle(‘Position’,pos,’Curvature’,[1 1]) axis equal but set the curvature of the rectangle to 1! The position vector defines the rectangle, the first two values x and … Read more

matplotlib savefig in jpeg format

You can save an image as ‘png’ and use the python imaging library (PIL) to convert this file to ‘jpg’: import Image import matplotlib.pyplot as plt plt.plot(range(10)) plt.savefig(‘testplot.png’) Image.open(‘testplot.png’).save(‘testplot.jpg’,’JPEG’) The original: The JPEG image:

Adding subplots to a subplot

You can nest your GridSpec using SubplotSpec. The outer grid will be a 2 x 2 and the inner grids will be 2 x 1. The following code should give you the basic idea. import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec fig = plt.figure(figsize=(10, 8)) outer = gridspec.GridSpec(2, 2, wspace=0.2, hspace=0.2) for i in … Read more

What are the differences between add_axes and add_subplot?

Common grounds Both, add_axes and add_subplot add an axes to a figure. They both return a (subclass of a) matplotlib.axes.Axes object. However, the mechanism which is used to add the axes differs substantially. add_axes The calling signature of add_axes is add_axes(rect), where rect is a list [x0, y0, width, height] denoting the lower left point … Read more

How to prevent numbers being changed to exponential form in a plot

The formatting of tick labels is controlled by a Formatter object, which assuming you haven’t done anything fancy will be a ScalerFormatterby default. This formatter will use a constant shift if the fractional change of the values visible is very small. To avoid this, simply turn it off: plt.plot(arange(0,100,10) + 1000, arange(0,100,10)) ax = plt.gca() … Read more