axes
How do I edit the axes of an image in MATLAB to reverse the direction?
To reverse an axis, you can set the ‘XDir’ or ‘YDir’ property of the current axes to ‘reverse’: set(gca,’XDir’,’reverse’); %# This flips the x axis Keep in mind that flipping an axis in this way flips everything in the plot as well. This probably isn’t what you want to do for the y axis. You … Read more
Removing axes margins in 3D plot
There is not property or method that can modify this margins. You need to patch the source code. Here is an example: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np ###patch start### from mpl_toolkits.mplot3d.axis3d import Axis if not hasattr(Axis, “_get_coord_info_old”): def _get_coord_info_new(self, renderer): mins, maxs, centers, deltas, tc, highs = self._get_coord_info_old(renderer) … Read more
How to get a matplotlib Axes instance
Use the gca (“get current axes”) helper function: ax = plt.gca() Example: import matplotlib.pyplot as plt import matplotlib.finance quotes = [(1, 5, 6, 7, 4), (2, 6, 9, 9, 6), (3, 9, 8, 10, 8), (4, 8, 8, 9, 8), (5, 8, 11, 13, 7)] ax = plt.gca() h = matplotlib.finance.candlestick(ax, quotes) plt.show()
How to set common axes labels for subplots
You can create a big subplot that covers the two subplots and then set the common labels. import random import matplotlib.pyplot as plt x = range(1, 101) y1 = [random.randint(1, 100) for _ in range(len(x))] y2 = [random.randint(1, 100) for _ in range(len(x))] fig = plt.figure() ax = fig.add_subplot(111) # The big subplot ax1 = … Read more
Changing the tick frequency on the x or y axis
You could explicitly set where you want to tick marks with plt.xticks: plt.xticks(np.arange(min(x), max(x)+1, 1.0)) For example, import numpy as np import matplotlib.pyplot as plt x = [0,5,9,10,15] y = [0,1,2,3,4] plt.plot(x,y) plt.xticks(np.arange(min(x), max(x)+1, 1.0)) plt.show() (np.arange was used rather than Python’s range function just in case min(x) and max(x) are floats instead of ints.) … Read more
Custom logarithmic axis scaling in matplotlib
The scale consists of two Transform classes, each of which needs to provide a transform_non_affine method. One class needs to transform from data to display coordinates, which would be log(a+1), the other is the inverse and needs to transform from display to data coordinates, which would in this case be exp(a)-1. Those methods need to … 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
Strange error with matplotlib axes labels
I had this same issue when working in iPython notebook. I think it can be re-created as follows: import matplotlib.pyplot as plt plt.ylabel=”somestring” # oh wait this isn’t the right syntax. … plt.ylabel(‘somestring’) # now this breaks because the function has been turned into a string Re-starting the kernel or re-importing the libraries restores plt.ylabel … Read more
Axes class – set explicitly size (width/height) of axes in given units
The axes size is determined by the figure size and the figure spacings, which can be set using figure.subplots_adjust(). In reverse this means that you can set the axes size by setting the figure size taking into acount the figure spacings: import matplotlib.pyplot as plt def set_size(w,h, ax=None): “”” w, h: width, height in inches … Read more