필자는 회선 일반화 알고리즘을 가지고 있으며 플롯에 허용 오차를 증가시키는 스크롤 막대를 추가하려고합니다 (i는 더 많은 일반화를 이루었습니다). matplotlib를 사용하면 어떻게 가능합니까?Matplotlib 스크롤 막대
요약하면, 나는 줄에서 공차 효과의 증가를 표시 할 슬라이더를 클릭하고 드래그 할 수 있기를 원합니다.
여전히 정말로 고심하고 있습니다. 나는 단지 1-10의 간단한 척도로 하나의 슬라이더 만 원한다.
그래 데모는
fig = mp.figure()
ax = fig.add_subplot(111)
fig.subplots_adjust(left=0.25, bottom=0.25)
min0=1
max0=10
tolerance = 0
chain1 = ChainLoader('Wiggle1.txt')
chain = chain1[0]
chain2 = chain.generalise(tolerance)
axcolor = 'lightgoldenrodyellow'
axmin = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axmax = fig.add_axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
tolerance = Slider(axmin, 'Min', 1, 10, valinit=min0)
#smax = Slider(axmax, 'Max', 0, 30000, valinit=max0)
def update(val):
tolerance = tolerance.val
#pp.show()
tolerance.on_changed(update)
#smax.on_changed(update)
chain2 = chain.generalise(tolerance)
pp.plotPolylines(chain2)
pp.show()
내 문제는 데프 업데이트 섹션을 작성하는 방법이다, 이것은 내가 지금까지 무엇을 가지고 난 그냥 일을 하나 개의 슬라이더를 얻을 struggerling있어, 도움이됩니다. 어떤 도움이 필요합니까?
from PointPlotter import PointPlotter
from ChainHandler import ChainLoader
pp=PointPlotter()
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
ax = plt.subplot(111)
plt.subplots_adjust(left=0.25, bottom=0.25)
tolerance = 0
f0 = 0
chain2 = ChainLoader('Wiggle1.txt')
for chain in chain2:
chain2 = chain.generalise(tolerance)
pp.plotPolylines(chain2)
axcolor = 'lightgoldenrodyellow'
axtol = plt.axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
tolerance = Slider(axtol, 'tol', 0.1, 30.0, valinit=f0)
def update(val):
tolerance = tolerance.val
for chain in chain2:
chain2 = chain.generalise(tolerance)
pp.plotPolylines(chain2)
pp.plotPolylines(chain2)
tolerance.on_changed(update)
plt.show()
너무 가까이! 그것의 플로팅,하지만 "UnboundLocalError : 지역 변수 '공차'이전에 할당 된 참조"스크롤 막대를 사용할 때 반환합니다. @tcaswell 어떤 도움?
데모가 도움이됩니까? 코드에 _ 특이한 문제가 있습니까? – tacaswell
수정 사항을 참조하십시오. 메모로, 만약 당신이 뭔가를 편집하고 그것에 대해 누군가의 관심을 끌고 싶다면, 주석에'@ 사용자 이름'을 넣으십시오 (예를 들어'@ tcaswell'은 나를 알릴 것입니다) – tacaswell