pycharmers.matplotlib.layout module

pycharmers.matplotlib.layout.FigAxes_create(fig=None, ax=None, figsize=6, 4, projection=None, nplots=1, ncols=1, nrows=1, axis=0, facecolor='white', **kwargs)[source]

Create a figure and a subplot (a set of subplots).

Parameters
  • fig (Figure) – The Figure instance.

  • ax (Axes) – The Axes instance.

  • figsize (tuple) – The figure size for 1 plot.

  • projection (str) – The projection type of the subplot.

  • nplots (int) – Total number of Plots.

  • nrows (int) – The number of rows

  • ncols (int) – The number of columns.

  • axis (int) – 0 or 1 Direction to arrange axes.

  • facecolor (str) – The background color. (default= "white" )

  • **kwargskwargs for add_subplot(*args, **kwargs) method of matplotlib.figure.Figure instance.

Returns

The Figure instance ax (Axes) : An array of Axes objects if more than one subplot was created.

Return type

fig (Figure)

Examples

>>> import matplotlib.pyplot as plt
>>> from pycharmers.matplotlib import FigAxes_create
>>> num_data = 10
>>> data = range(num_data)
>>> fig, axes = FigAxes_create(nplots=num_data, ncols=4, figsize=(4,4))
>>> for x,ax in zip(data,axes):
...     ax.scatter(x,x,s=x+1)
>>> plt.show()
pycharmers.matplotlib.layout.set_ax_info(ax, **kwargs)[source]

Set Axes information

Parameters
  • ax (Axes) – The Axes instance.

  • kwargskey indicate the method which is start with set_, and the method takes arguments (val) according to the type of val

Returns

The Axes instance.

Return type

ax (Axes)

Examples

>>> import matplotlib.pyplot as plt
>>> from pycharmers.matplotlib import set_ax_info
>>> fig, ax = plt.subplots(nplots=1)[0]
>>> ax = set_ax_info(ax, aspect=5, title="Title", xlabel="Xlabel", ylabel="Ylabel", yticks={"ticks":[]})
>>> ax.scatter(1,1)
>>> plt.show()
pycharmers.matplotlib.layout.clear_grid(ax, pos=['x', 'y'])[source]

Clear a grid

Parameters
  • ax (Axes) – The Axes instance.

  • pos (list) – Positions to clean a grid

Examples

>>> from pyutils.matplotlib import clear_grid, FigAxes_create
>>> fig,ax = FigAxes_create(nplots=1)[0]
>>> ax = clear_grid(ax=ax, pos=["x", "y"])
>>> ax = clear_grid(ax=ax, pos=list("ltrb"))
pycharmers.matplotlib.layout.measure_canvas(nplots, ncols=2, figsize=6, 4)[source]

Measure Canvas size.

Parameters
  • nplots (int) – Total number of figures.

  • ncols (int) – The number of columns.

  • figsize (tuple) – The figure size for 1 plot.

Returns

The number of columns. nrows (int) : The number of rows. total_figsize (tuple) : The total figure size.

Return type

ncols (int)

Examples

>>> import matplotlib.pyplot as plt
>>> from pycharmers.matplotlib import measure_canvas
>>> num_data = 10
>>> data = range(num_data)
>>> ncols, nrows, total_figsize = measure_canvas(nplots=num_data, ncols=4, figsize=(4,4))
>>> fig, axes = plt.subplots(nrows=nrows, ncols=ncols, sharex="all", sharey="all", figsize=total_figsize)
>>> plot_all = False
>>> for i,ax_row in enumerate(axes):
...     for j,ax in enumerate(ax_row):
...         idx = i*ncols+j
...         if idx>=num_data:
...             plot_all = True
...         if plot_all:
...             fig.delaxes(ax)
...         else:
...             x = data[idx]+1
...             ax.scatter(x,x,s=x*10)
>>> plt.show()
pycharmers.matplotlib.layout.show_all_fonts()[source]

Show all fonts available in matplotlib .

pycharmers.matplotlib.layout.mpljapanize(font_family='IPAMincho')[source]

Make matplotlib compatible with Japanese