By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,969 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,969 IT Pros & Developers. It's quick & easy.

matplotlib+numpy

P: 1
My problem statement is the following:
Use NumPy and Matplotlib to draw a scatterplot of uniform random (x, y) values all drawn from the [0, 1] interval.

The following is what I have tried:
Expand|Select|Wrap|Line Numbers
  1. import matplotlib.pyplot as plt
  2.  
  3. import numpy as np
  4.  
  5. import random
  6.  
  7. # Fixing random state for reproducibility
  8.  
  9. np.random.seed(19680801)
  10.  
  11. N = 50
  12.  
  13. x = random.uniform(0, 1)
  14. y = random.uniform(0, 1)
  15.  
  16. colors = random.uniform(0, 1)
  17.  
  18. #for ...
  19.  
  20. plt.scatter(x, y, s=area, c=colors, alpha=0.5)
  21. plt.title('Exercise 2 - Drawing a plot')
  22. plt.xlabel('x')
  23. plt.ylabel('y')
  24. plt.show()
  25.  
The output of the above is my plot with a single large dot in the center.
For some reason I am only generating and plotting a single x,y pair.
I think I need a for loop but I lack knowledge of matplotlib+numpy.

Is anyone able to help me with this?
Sep 17 '18 #1
Share this Question
Share on Google+
1 Reply


P: 1
Use list comprehension to generate a list of values!

```
x = [random.uniform(0, 1) for x in range(100)]
y = [random.uniform(0, 1) for x in range(100)]
```
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.