matplotlib Python上的对数y轴图

3yhwsihp  于 2023-03-30  发布在  Python
关注(0)|答案(1)|浏览(175)

我尝试用Python以对数标度绘图,我想通过将10^-1和所有值重新排列y轴值,而不是得到x1c 0d1x
其中10^-1对所有值重复。我需要它来缩小一点图。
非常感谢您的帮助!(对不起,这个问题已经解决了)

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from scipy.interpolate import griddata, UnivariateSpline
from matplotlib.pyplot import * # plotting library
import math

plt.rcParams.update({
    'text.usetex': True,
    'font.family':'serif',
    'mathtext.fontset' : 'cm',
    'mathtext.rm': 'serif',
    'font.weight': 'normal',
    'axes.labelweight': 'normal',
    'axes.linewidth': 1.5,
    'xtick.major.width': 1.5,
    'xtick.major.size': 10.0,
    'xtick.minor.size': 5.0,
    'ytick.major.width': 1.5,
    'ytick.major.size': 10.0,
    'ytick.minor.size': 5.0,
    'font.size': 30})
plt.rcParams.update({'font.size': 20})

from matplotlib.pyplot import * # plotting library
import pylab
from matplotlib import ticker
from mpmath import mp
import mpmath

Lx_array=[200,220,240,260,280,300,320,340,360,380]

fc[0]= [0.12157595414600386, 0.12041770132162587, 0.12047596487921948, 0.12052880984177164, 0.12057638017580277, 0.12061976850950093, 0.12065915948174381, 0.12069532559157949, 0.12072842279963499,0.12140365733314845]
xfitplot[0]= [200.0, 380.0] #range of L_x
yfitplot[0] = [0.12048675725819148, 0.00041285587251701833] #parameters fit

fig = plt.figure(figsize = (10.0,8.0))
subplot(221)
ax=matplotlib.pyplot.gca()

#---------
errorbar(Lx_array,fc[0],fmt='s',ms=10,label=r"$a)$")
plot([Lx_array[0],Lx_array[-1]],[yfitplot[0][0]*Lx_array[0]**yfitplot[0][1], yfitplot[0][0]*Lx_array[-1]**yfitplot[0][1]],'r--',lw=4)
for axis in ['top','bottom','left','right']:
    ax.spines[axis].set_linewidth(1.5)
#ax.tick_params('both', length=8, width=1.5, which='major', pad=10)
#ax.tick_params('both', length=4, width=1.5, which='minor', pad=10)
ax.set_xscale('log')
ax.set_yscale('log')
ax.tick_params(direction='in')
ax.tick_params(direction='in',which='minor')
ylabel(r'$f_c$',fontsize=30)
xticks(size=25)
yticks(size=25)
plt.legend(loc='upper right',fontsize=20)
#plt.tight_layout()
k97glaaz

k97glaaz1#

我只使用标量格式化程序:

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

x = [200,220,240,260,280,300,320,340,360,380]
fc = [0.12157595414600386, 0.12041770132162587, 0.12047596487921948, 0.12052880984177164, 0.12057638017580277,
      0.12061976850950093, 0.12065915948174381, 0.12069532559157949, 0.12072842279963499,0.12140365733314845]

fig, axs = plt.subplots(2, 2, figsize=(5.0, 4.0), layout='constrained')
ax = axs[0, 0]

ax.loglog(x, fc, 's')
ax.set_xscale('log')
ax.set_yscale('log')

ax.yaxis.set_minor_formatter(mticker.ScalarFormatter())

plt.show()

相关问题