【发布时间】:2020-05-24 16:01:14
【问题描述】:
当我在这里运行我的代码时:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from matplotlib.widgets import RadioButtons
from matplotlib.widgets import Slider
%matplotlib notebook
# generate 4 random variables from the random, gamma, exponential, and uniform distributions
sample_size = 10000
normal = np.random.normal(loc=0.0, scale=1.0, size=sample_size)
gamma = np.random.gamma(shape = 1.0, scale=1.0, size=sample_size)
uniform = np.random.uniform(low=0.0, high=10.0, size=sample_size)
exponential = np.random.exponential(scale=1.0, size=sample_size)
axcolor = 'lightgoldenrodyellow'
rax = plt.axes([0.05, 0.7, 0.25, 0.25], facecolor=axcolor)
radio = RadioButtons(rax, ('Normal', 'Gamma', 'Uniform', 'Exponential'))
def dist_func(type_l):
dist_dict = {'Normal':normal, 'Gamma':gamma, 'Uniform':uniform, 'Exponential':exponential}
data_type = dist_dict[type_l]
hist = plt.hist(data_type,bins=100, axes=hax)
plt.draw()
radio.on_clicked(dist_func)
我的直方图显示在使用单选按钮定义的轴内,我希望它显示为正常的直方图,其中 matplotlib 获取轴值。
有什么办法可以做到吗?
【问题讨论】:
-
你的
axes=hax中的hax是什么? -
抱歉,我尝试为直方图制作另一个坐标轴>
标签: python matplotlib