Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

python - ValueError Issue with implementation of plotting uniform distribution

so i am trying to plot a uniform distribution using scipy.stats, but am running into this error, to do with shape transformation, could someone please tell me why this is happening / how my code should look, thank you.

Full Code and traceback below:

# UNIFORM DISTRIBUTION:

from scipy.stats import uniform
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

n = 10  # total data number

x = list(range(0, n + 1))

# create a list of values that follow uniform distribution
r = uniform.rvs(size=1000)
ax.vlines(x, 0, r, colors = "blue")
plt.show()

FULL TRACEBACK:

ValueError Traceback (most recent call last) in 12 # create a list of values that follow uniform distribution 13 r = uniform.rvs(size=1000) ---> 14 ax.vlines(x, 0, r, colors = "blue") 15 plt.show() 16

matplotlib_init_.py in inner(ax, data, *args, **kwargs) 1436 def inner(ax, *args, data=None, **kwargs): 1437 if data is None: -> 1438 return func(ax, *map(sanitize_sequence, args), **kwargs) 1439 1440 bound = new_sig.bind(ax, *args, **kwargs)

matplotlibaxes_axes.py in vlines(self, x, ymin, ymax, colors, linestyles, label, **kwargs)
1257 masked_verts[:, 0, 1] = ymin 1258
masked_verts[:, 1, 0] = x -> 1259 masked_verts[:, 1, 1] = ymax 1260 1261 lines = mcoll.LineCollection(masked_verts, colors=colors,

umpymacore.py in setitem(self, indx, value) 3378 if _mask is nomask: 3379 # Set the data, then the mask -> 3380 _data[indx] = dval 3381 if mval is not nomask: 3382 _mask = self._mask = make_mask_none(self.shape, _dtype)

ValueError: could not broadcast input array from shape (1000) into shape (11)

question from:https://stackoverflow.com/questions/65862162/valueerror-issue-with-implementation-of-plotting-uniform-distribution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...