簡體   English   中英

Matplotlib 的“symlog”選項:如何防止曲線“回來”?

[英]Matplotlib's “symlog” option: how to prevent curves that “come back”?

我正在繪制 x 范圍內從 -1000 到 1000 的數據。但我只對 x = -1 和 0 之間的值感興趣。

我還想在 x 對數刻度上 plot。 但由於 x 值為負,我不能使用 xscale("log")。 我可以使用 xscale("symlog") ,這是我想要的行為。

不幸的是,“symlog”似乎被破壞了。 我不能使用值小於 2(默認值?)的 linthreshx 參數。 但由於我對從 -1 到 0 的 x 值感興趣,所以我必須使用該參數並將其設置為 1e-5 甚至更小。

如果我將 linthreshx 設置為小於 1 的值,則 plot 會中斷。 這是一個簡單的例子,取自What is the difference between 'log' and 'symlog'?

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))

pyplot.axis([-60,60,-1.5,1.5])

pyplot.xscale('symlog', linthreshx=0.1)

運行它你會明白我所說的曲線“回來”是什么意思......這是生成的圖像:結果

問題似乎是,在 x 軸上,0 實際上是 10^0 = 1,而不是 0。將小於 1 的值放置將使 go 線返回並且軸值錯誤(當用鼠標懸停並獲取x 值)。

我可能沒有使用正確的工具,但如何實現我想要的? 我希望 x 軸看起來像:-10^2 -10^1 -10^0 -10^-1 -10^-2 -10^-3... [達到我定義的最小指數]... 10^-3 10^-2 10^-1 10^0 10^1 10^2

謝謝

這實際上是 matplotlib 中的一個錯誤。

https://github.com/matplotlib/matplotlib/issues/396

現在已修復。 我附上了一張圖片,顯示了上一個片段的正確結果。結果正確

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM