I made a random number graph with Numpy

Import the required libraries

import numpy as np
import matplotlib.pyplot as pp 

Set x-axis and y-axis

x = np.arange(11)
y = np.random.randint(100, size = 11)

Numerical values are arranged from 0 to 10 on the x-axis. On the y-axis, 10 arrays consisting of random numbers from 0 to 100 are arranged.

Draw a graph

pp.plot(x, y)
pp.axis([0, 10, 0, 100])
pp.xticks([dg for dg in np.arange(11)])
pp.grid(True)

The data is plotted on the first line. The second line specifies the x-axis display range and the y-axis display range. The third line has one scale on the x-axis. By the way, if you want to specify the scale on the y-axis as well, use the yticks function. Then, a grid is created from the scale with the grid function that takes True as an argument on the fourth line.

Output graph

pp.show()

The following code can be summarized up to this point.

randplot.py


import numpy as np
import matplotlib.pyplot as pp 

x = np.arange(11)
y = np.random.randint(100, size = 11)

pp.plot(x, y)
pp.axis([0, 10, 0, 100])
pp.xticks([dg for dg in np.arange(11)])
pp.grid(True)

pp.show()

Click here for the completed graph スクリーンショット 2017-05-06 1.33.59.png

Recommended Posts

I made a random number graph with Numpy
I made a life game with Numpy
I made a fortune with Python.
I made a daemon with Python
I made a character counter with Python
I made a Hex map with Python
I made a stamp generator with GAN
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
〇✕ I made a game
I made a GUI application with Python + PyQt5
A memo that made a graph animated with plotly
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a simple Bitcoin wallet with pycoin
I made a LINE Bot with Serverless Framework!
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a QR code image with CuteR
[AWS] I made a reminder BOT with LINE WORKS
I made a prime number generation program in Python
I made a household account book bot with LINE Bot
I made a Christmas tree lighting game with Python
I made a vim learning game "PacVim" with Go
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
Create a random number with an arbitrary probability density
I made a prime number generation program in Python 2
I made a falling block game with Sense HAT
I wrote GP with numpy
Draw a graph with NetworkX
I made blackjack with python!
Numpy random module random number generator
I made a python text
I made a discord bot
I made COVID19_simulator with JupyterLab
I made Word2Vec with Pytorch
I made blackjack with Python.
Draw a graph with networkx
I made wordcloud with Python.
I made a LINE BOT that returns parrots with Go
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
I made a puzzle game (like) with Tkinter in Python
I made a rigid Pomodoro timer that works with CUI
I made a surveillance camera with my first Raspberry PI.
I made a plug-in that can "Daruma-san fell" with Minecraft
[AWS] I made a reminder BOT with LINE WORKS (implementation)
I made a C ++ learning site
Draw a graph with Julia + PyQtGraph (2)
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
Draw a loose graph with matplotlib
Draw a graph with Julia + PyQtGraph (1)
I made a CUI-based translation script