Matplotlib axis with two scales shared origin

use the align_yaxis() function: import numpy as np import matplotlib.pyplot as plt def align_yaxis(ax1, v1, ax2, v2): “””adjust ax2 ylimit so that v2 in ax2 is aligned to v1 in ax1″”” _, y1 = ax1.transData.transform((0, v1)) _, y2 = ax2.transData.transform((0, v2)) inv = ax2.transData.inverted() _, dy = inv.transform((0, 0)) – inv.transform((0, y1-y2)) miny, maxy = … Read more

How to display all minor tick marks on a semi-log plot

solution for matplotlib >= 2.0.2 Let’s consider the following example which is produced by this code: import matplotlib.pyplot as plt import matplotlib.ticker import numpy as np y = np.arange(12) x = 10.0**y fig, ax=plt.subplots() ax.plot(x,y) ax.set_xscale(“log”) plt.show() The minor ticklabels are indeed gone and usual ways to show them (like plt.tick_params(axis=”x”, which=”minor”)) fail. The first … Read more

Setting the position of the `ylabel`

You can move the ylabel using ax.yaxis.set_label_coords, which does accept negative numbers. For your example, I removed the line with set_label_position, and added: axPres.yaxis.set_label_coords(-0.1,1.02) From the documentation: Axis.set_label_coords(x, y, transform=None) Set the coordinates of the label. By default, the x coordinate of the y label and the y coordinate of the x label are determined … Read more