>  기사  >  백엔드 개발  >  향상된 데이터 시각화를 위해 하위 플롯 Y축 범위를 설정하는 방법은 무엇입니까?

향상된 데이터 시각화를 위해 하위 플롯 Y축 범위를 설정하는 방법은 무엇입니까?

DDD
DDD원래의
2024-10-18 12:04:16778검색

How to Set Subplot Y-Axis Range for Improved Data Visualization?

Setting the Subplot Axis Range

When visualizing data using subplots, it is often necessary to adjust the axis range to enhance readability. This article addresses the question of how to set the y-axis range of a specific subplot.

In the example provided, the FFT plot contains an overly large spike that obscures the underlying data. To rectify this, we need to restrict the y-axis range to a sensible interval.

The attempted code:

<code class="python">pylab.ylim([0,1000])</code>

fails because the statement is executed before the subplot is created. The correct placement is after the pylab.plot() command.

<code class="python">pylab.subplot(h,w,2)
pylab.title("FFT")
fft = scipy.fft(rawsignal)
pylab.plot(abs(fft))
pylab.ylim([0,1000])</code>

Additionally, since the use of pylab is now deprecated by Matplotlib, it is recommended to use the pyplot interface instead:

<code class="python">import matplotlib.pyplot as plt

# Set the y-axis range for the second subplot
plt.subplot(h, w, 2)
plt.title("FFT")
fft = scipy.fft(rawsignal)
plt.plot(abs(fft))
plt.ylim([0, 1000])</code>

By following these recommendations, you can effectively set the axis range for your subplots and improve the visualization of your data.

위 내용은 향상된 데이터 시각화를 위해 하위 플롯 Y축 범위를 설정하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.