Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在符号图中保持刻度之间的长度相同?_Python_Python 2.7_Numpy_Matplotlib - Fatal编程技术网

Python 如何在符号图中保持刻度之间的长度相同?

Python 如何在符号图中保持刻度之间的长度相同?,python,python-2.7,numpy,matplotlib,Python,Python 2.7,Numpy,Matplotlib,我做了一个symlog图,因为我想在一些量为负的情况下以对数比例绘制。但是y轴的刻度被弄乱了。刻度之间的长度不同。这是我为绘图而编写的代码: import numpy as np import matplotlib.pyplot as plt from matplotlib import rc import uncertainties from uncertainties import ufloat from uncertainties.umath import * import uncerta

我做了一个symlog图,因为我想在一些量为负的情况下以对数比例绘制。但是y轴的刻度被弄乱了。刻度之间的长度不同。这是我为绘图而编写的代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import uncertainties
from uncertainties import ufloat
from uncertainties.umath import *
import uncertainties.unumpy as unp

ANISO_POLY=['2','3','4','5']
ST_INT=['3','4','5']
for st in ST_INT:
        j=0
        rc('text', usetex=True)
        rc('font', family='serif')
        fig = plt.figure()
        ax = fig.add_subplot(1,1,1)
        ax.set_xscale('symlog')
        ax.set_yscale('symlog', linthreshy=0.004)

        for aniso in ANISO_POLY:
            correlationGalStarfile='/ST_INTEG_LIM.'+st+'.ANIS_POLY_ORD.'+aniso+'/xi.resample.cat'
            cor=np.loadtxt(correlationGalStarfile)
            Theta=cor[:,0]
            GSPlus=cor[:,1];GSPlusErr=cor[:,5]
            correlationStarfile='ST_INTEG_LIM.'+st+'.ANIS_POLY_ORD.'+aniso+'/xi.cat'
            scor=np.loadtxt(correlationfile)
            SSPlus=scor[:,1];SSPlusErr=scor[:,5]
            GSC = unp.uarray(GSPlus, GSPlusErr)
            SSC = unp.uarray(SSCorPlus, SSPlusErr)
            ratio=GSC*abs(GSC)/SSC
            ErrorXi=unp.std_devs(ratio)
            Xi=unp.nominal_values(ratio)
            ax.errorbar(Theta, Xi, yerr=ErrorXi,  fmt='-', color=colors[j], ecolor=colors[j],  capsize=2, capthick=None,label='aniso. poly. ord. '+aniso)
            j+=1

        ax.set_xlabel(r'$\Theta$', fontsize=20)
        ax.set_ylabel(r'$\xi^{+}_{sys}$', fontsize=20)
        ax.set_title('stellar integration limit '+st)
        ax.set_ylim(-5e-4,5e-4)
        ax.set_yticks((-1e-4,-1e-5,0.0,1e-5,1e-4))
        ax.set_yticklabels([r'$-10^{-4}$',r'$-10^{-5}$' , r'$0.0$', r'$10^{-5}$',r'$10^{-4}$'])

        fontsize=15
        for tick in ax.xaxis.get_major_ticks():
            tick.label1.set_fontsize(fontsize)
        for tick in ax.yaxis.get_major_ticks():
            tick.label1.set_fontsize(fontsize)            
        leg=plt.legend(numpoints=1,loc='upper right', ncol=1,fontsize=15)
        leg.draw_frame(False)
        plotfile='Correlation.SIL.'+st+'.pdf'
        plt.savefig(plotfile, dpi=50, bbox_inches='tight')
        plt.close()
输出图如下所示:


如何定义刻度之间的距离?

这是因为您指定了
linthreshy

如果指定包含记号位置的线性阈值,则会看到接近0的线性比例对记号位置的影响

作为复制它的快速示例:

import matplotlib.pyplot as plt

plt.rc('axes', labelsize=20)

fig, ax = plt.subplots()
ax.set(xscale='symlog', xlabel=r'$\Theta$', ylabel=r'$\xi^{+}_{sys}$')
ax.set_yscale('symlog', linthreshy=0.004)
ax.set_yticks([-1e-4, -1e-5, 0.0, 1e-5, 1e-4])
ax.tick_params(labelsize=15)

ax.axis([1e-1, 1e2, -10**-3.5, 10**-3.5])

fig.tight_layout()
plt.show()

如果我们只是将
linthreshy
更改为小于您手动指定的刻度位置,您将看不到线性刻度的效果。此代码的唯一区别是
linthreshy=1e-5

import matplotlib.pyplot as plt

plt.rc('axes', labelsize=20)

fig, ax = plt.subplots()
ax.set(xscale='symlog', xlabel=r'$\Theta$', ylabel=r'$\xi^{+}_{sys}$')
ax.set_yscale('symlog', linthreshy=1e-5)
ax.set_yticks([-1e-4, -1e-5, 0.0, 1e-5, 1e-4])
ax.tick_params(labelsize=15)

ax.axis([1e-1, 1e2, -10**-3.5, 10**-3.5])

fig.tight_layout()
plt.show()