log와 symlog의 차이점은 무엇입니까?
matplotlib에서는 또는 를 사용하여 축 스케일링을 설정할 수 있습니다. 두 함수 모두 세 가지 다른 스케일을 허용합니다.'linear'
|'log'
|'symlog'
.
사이의 차이점은 무엇입니까?'log'
그리고.'symlog'
? 제가 한 간단한 테스트에서 둘 다 똑같이 생겼습니다.
설명서에 다른 매개변수를 허용한다고 나와 있는 것은 알지만, 여전히 그들 사이의 차이를 이해하지 못합니다.누가 설명해 주실 수 있습니까?샘플 코드와 그래픽이 있으면 답이 가장 좋을 것 같습니다! (또한: 'symlog'라는 이름은 어디서 유래된 것입니까?)
저는 마침내 그들 사이의 차이를 이해하기 위해 몇 가지 실험을 할 시간을 가졌습니다.제가 발견한 것은 다음과 같습니다.
log
양의 값만 허용하고, 음의 값을 처리하는 방법을 선택할 수 있습니다 (mask
아니면clip
).symlog
는 대칭 로그를 의미하며 양과 음의 값을 허용합니다.symlog
그림 내에서 0 주위의 범위를 설정할 수 있습니다. 로그가 아닌 선형이 됩니다.
그래픽과 예제를 사용하면 모든 것이 훨씬 더 쉽게 이해될 수 있을 것으로 생각합니다. 따라서 다음과 같이 시도해 보겠습니다.
import numpy
from matplotlib import pyplot
# Enable interactive mode
pyplot.ion()
# Draw the grid lines
pyplot.grid(True)
# Numbers from -50 to 50, with 0.1 as step
xdomain = numpy.arange(-50,50, 0.1)
# Plots a simple linear function 'f(x) = x'
pyplot.plot(xdomain, xdomain)
# Plots 'sin(x)'
pyplot.plot(xdomain, numpy.sin(xdomain))
# 'linear' is the default mode, so this next line is redundant:
pyplot.xscale('linear')
# How to treat negative values?
# 'mask' will treat negative values as invalid
# 'mask' is the default, so the next two lines are equivalent
pyplot.xscale('log')
pyplot.xscale('log', nonposx='mask')
# 'clip' will map all negative values a very small positive one
pyplot.xscale('log', nonposx='clip')
# 'symlog' scaling, however, handles negative values nicely
pyplot.xscale('symlog')
# And you can even set a linear range around zero
pyplot.xscale('symlog', linthreshx=20)
완성도를 위해 다음 코드를 사용하여 각 수치를 저장했습니다.
# Default dpi is 80
pyplot.savefig('matplotlib_xscale_linear.png', dpi=50, bbox_inches='tight')
다음을 사용하여 도형 크기를 변경할 수 있습니다.
fig = pyplot.gcf()
fig.set_size_inches([4., 3.])
# Default size: [8., 6.]
(만약 제가 제 질문에 대답하는 것이 확실하지 않다면, 이 글을 읽어보세요.)
symlog는 로그와 같지만 그림이 선형인 0 근처의 값 범위를 정의하여 0 근처의 무한대로 가지 않도록 할 수 있습니다.
출처: http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xscale
로그 그래프에서 영값은 절대 가질 수 없으며, 0에 가까운 값을 가지면 영값은 그래프의 아래쪽으로 급격히 내려가게 됩니다(영점에 가까워짐). 왜냐하면 "log(영점에 가까워짐)"를 취할 때 "음의 무한대에 가까워짐"을 알 수 있기 때문입니다.
symlog는 로그 그래프를 사용하고자 하는 상황에서 도움이 되지만 값이 때때로 0으로 떨어지거나 0으로 떨어질 수 있지만 그래프에 의미 있는 방법으로 표시할 수 있기를 원하는 경우입니다.symlog가 필요하시면 아실 겁니다.
다음은 symlog가 필요한 경우의 동작 예입니다.
초기 그림, 축척이 아닙니다.x~0에서 몇 개의 점이 군집하는지 주목합니다.
ax = sns.scatterplot(x= 'Score', y ='Total Amount Deposited', data = df, hue = 'Predicted Category')
['
로그 축척 그림.모든 것이 무너졌습니다.
ax = sns.scatterplot(x= 'Score', y ='Total Amount Deposited', data = df, hue = 'Predicted Category')
ax.set_xscale('log')
ax.set_yscale('log')
ax.set(xlabel='Score, log', ylabel='Total Amount Deposited, log')
'
왜 무너졌나요?x축의 일부 값이 0에 매우 가깝거나 같기 때문입니다.
Symlog 축척 그림.모든 것이 정상입니다.
ax = sns.scatterplot(x= 'Score', y ='Total Amount Deposited', data = df, hue = 'Predicted Category')
ax.set_xscale('symlog')
ax.set_yscale('symlog')
ax.set(xlabel='Score, symlog', ylabel='Total Amount Deposited, symlog')
언급URL : https://stackoverflow.com/questions/3305865/what-is-the-difference-between-log-and-symlog
'programing' 카테고리의 다른 글
열에서 항목 발생 빈도를 백분율로 가져옵니다. (0) | 2023.09.14 |
---|---|
XML에서 특성 값 가져오기 (0) | 2023.09.14 |
regex, 일치하지 않는 경우 처리 사례에 대해 첫 번째 일치가 있는 문자열 반환 (0) | 2023.09.09 |
사용자를 변경하려면 어떻게 해야 합니까?(cmd, mariadb) (0) | 2023.09.09 |
도커 로그인: '스터브가 잘못된 데이터를 수신했습니다' 자격 증명을 저장하는 중 오류가 발생했습니다. (0) | 2023.09.09 |