0

I've generated a lot of numbers using Python, saving them in a list, and now I want to plot them in a scatter graph and a bar graph to see the patterns of the function that I created.

I'm getting numbers from 0 to 99,999,999 at maximum, I tried to plot but I failed.

In the bar graph the y axis should show how many times a number repeated itself in the range of the numbers generated and the x axis the number itself.

I tried to use the method collections.counter but it keeps returning me a dict with all the numbers that appeard at least one time in the list, instead of the ones that just repeated, with the data of the numbers that repeated I think I could plot the graph properly.

Image showing the data that i get from the function

Image showing the data that i get from the function

gboffi
  • 22,939
  • 8
  • 54
  • 85
  • 3
    One of your problems is that you store the numbers as strings instead of as numbers. – JohanC Jan 28 '22 at 21:10
  • i also have a list with all of them, just int numbers, but i needed to use another function to get the number that each one repeats itself in a dictionary, i don't know if it is the most efficient way – Lucca Machado Jan 28 '22 at 21:19
  • For the dictionary, it is much better to create it using the integers directly as key, without converting them to strings. – JohanC Jan 28 '22 at 22:59
  • 1
    I had a look at your _data-in-a-picture_, and well, except two numbers that have a count of two all the others appears only once in your list. I don't understand what you want to do, honest… Could you try to be more clear wrt what you want, especially with yourself? – gboffi Jan 29 '22 at 09:30
  • basically i'm creating a function that will try to create random numbers, without using any library, then i'm storing them into a vector, i would like to have a graph that shows the numbers and if they repeat themselves but i can't figure how, i tried to use the collections.counter to get a dictionary with just the numbers that appears more than one time so i could plot in the graph – Lucca Machado Jan 30 '22 at 15:02

1 Answers1

1

What would you like to plot in the scatter graph? Matplotlib has built-in histogram plotter.

import random
import matplotlib.pyplot as plt

random.seed(0)

ITER = 20
LOW = 0
HIGH = 10

RND_NUMS = []
for _ in range(ITER):
    RND_NUMS.append(random.randint(LOW, HIGH))

plt.hist(RND_NUMS, bins=range(0,10))

This produces something like:

histogram

DanielTuzes
  • 2,494
  • 24
  • 40