Axes from plt.subplots() is a “numpy.ndarray” object and has no attribute “plot”

If you debug your program by simply printing ax, you’ll quickly find out that ax is a two-dimensional array: one dimension for the rows, one for the columns. Thus, you need two indices to index ax to retrieve the actual AxesSubplot instance, like: ax[1,1].plot(…) If you want to iterate through the subplots in the way … Read more

How to make an axes occupy multiple subplots with pyplot

You can simply do: import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 7, 0.01) plt.subplot(2, 1, 1) plt.plot(x, np.sin(x)) plt.subplot(2, 2, 3) plt.plot(x, np.cos(x)) plt.subplot(2, 2, 4) plt.plot(x, np.sin(x)*np.cos(x)) i.e., the first plot is really a plot in the upper half (the figure is only divided into 2×1 = 2 cells), and … Read more

Embedding small plots inside subplots in matplotlib

I wrote a function very similar to plt.axes. You could use it for plotting yours sub-subplots. There is an example… import matplotlib.pyplot as plt import numpy as np #def add_subplot_axes(ax,rect,facecolor=”w”): # matplotlib 2.0+ def add_subplot_axes(ax,rect,axisbg=’w’): fig = plt.gcf() box = ax.get_position() width = box.width height = box.height inax_position = ax.transAxes.transform(rect[0:2]) transFigure = fig.transFigure.inverted() infig_position = … Read more

How do I change matplotlib’s subplot projection of an existing axis?

You can’t change the projection of an existing axes, the reason is given below. However the solution to your underlying problem is simply to use the subplot_kw argument to plt.subplots() described in the matplotlib documentation here. For example, if you wanted all your subplots to have the cartopy.crs.PlateCarree projection you could do import matplotlib.pyplot as … 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 set xticks in subplots

There are two ways: Use the axes methods of the subplot object (e.g. ax.set_xticks and ax.set_xticklabels) or Use plt.sca to set the current axes for the pyplot state machine (i.e. the plt interface). As an example (this also illustrates using setp to change the properties of all of the subplots): import matplotlib.pyplot as plt fig, … Read more

How can I make a blank subplot in matplotlib?

You could always hide the axes which you do not need. For example, the following code turns off the 6th axes completely: import matplotlib.pyplot as plt hf, ha = plt.subplots(3,2) ha[-1, -1].axis(‘off’) plt.show() and results in the following figure: Alternatively, see the accepted answer to the question Hiding axis text in matplotlib plots for a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)