我试图将轴固定为两个不同数据集的科学记数,其中一个是[1-9] x1e-3,另一个是[1-9] x1e-4.我想将两个轴设置为10 ^ -4并且在十进制之后具有一位数(例如%.1e).这是一个我试图玩的简单版本:我希望轴上的数字至少为1,我希望两种力量都相同.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(1,9,9)
y1 = x*10**(-4)
y2 = x*10**(-3)
fig, ax = plt.subplots(2,1,sharex=True)
ax[0].plot(x,y1)
ax[0].ticklabel_format(axis='y', style='sci', scilimits=(-4,-4))
ax[0].yaxis.major.formatter._useMathText = True
ax[1].plot(x,y2)
ax[1].ticklabel_format(axis='y', style='sci', scilimits=(-4,-4))
ax[1].yaxis.major.formatter._useMathText = True
plt.show()
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 Matplotlib 中使用偏移文本中的比例绘制 3D 图形。为此,我使用了ImportanceOfBeingErnest 的自定义轴主要格式化程序,以便将此比例设为乳胶格式:
\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport matplotlib.ticker as ticker\nfrom mpl_toolkits.mplot3d import Axes3D \nfrom matplotlib import cm\nimport numpy as np\n\nclass OOMFormatter(matplotlib.ticker.ScalarFormatter):\n def __init__(self, order=0, fformat="%1.1f", offset=True, mathText=True):\n self.oom = order\n self.fformat = fformat\n matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText)\n def _set_order_of_magnitude(self):\n self.orderOfMagnitude = self.oom\n def _set_format(self, vmin=None, vmax=None):\n self.format = self.fformat\n if self._useMathText:\n self.format = r\'$\\mathdefault{%s}$\' % self.format\n\n\nx = np.linspace(0, 22, 23)\ny = np.linspace(-10, 10, 21)\nX, Y = np.meshgrid(x, y)\nV = -(np.cos(X/10)*np.cos(Y/10))**2*1e-4\n\nfig, ax = plt.subplots(subplot_kw={"projection": "3d"})\nsurf = ax.plot_surface(X, …Run Code Online (Sandbox Code Playgroud) 我有一些数据绘制,我强制科学记数法的权力为10(而不是指数).下面是一段代码:
import matplotlib.ticker as mticker
formatter = mticker.ScalarFormatter(useMathText=True)
formatter.set_powerlimits((-3,2))
ax.yaxis.set_major_formatter(formatter)
Run Code Online (Sandbox Code Playgroud)
但是,x10 ^ -4的比例因子出现在图的左上角.
是否有一种简单的方法可以强制将此比例因子的位置放在y标签旁边,如下图所示?