Create an elliptical scatter plot in Python without using a multivariate normal distribution

Introduction

On machine learning sites, we often see plots of points in an ellipse. I didn't know how to make it, so I tried to make it by playing with Numpy.

code

ellipseLike.py


import numpy as np
import matplotlib.pyplot as plt

#Number of outputs
n = 1000

#Generate random numbers
x = np.random.uniform(-4, 4, n)
y = np.random.uniform(-1, 1, n)

#filtering
coordinates = np.array([((x[i])**2 + (y[i])**2)**(1/2) < 1 for i in range(n)])
index = np.where(coordinates==True)

#Manipulate coordinates
x_points = x[index] *4
y_points = y[index]

#Rotate and move coordinates(30 degrees)
x_points2 = x_points * (3**(1/2)) - y_points * (1/2)
y_points2 = x_points * (1/2) + y_points * (3**(1/2))

#plot
plt.scatter(x_points2, y_points2)
plt.show()

result

ellipse.png

in conclusion

I learned about the multivariate normal distribution after I finished making it. I didn't study enough ...

Thank you for visiting. If you have any comments or suggestions, please do not hesitate to contact us.

Recommended Posts

Create an elliptical scatter plot in Python without using a multivariate normal distribution
Create a standard normal distribution graph in Python
Plot and understand the multivariate normal distribution in Python
Create a GIF file using Pillow in Python
Create a MIDI file in Python using pretty_midi
Create a data collection bot in Python using Selenium
[Python] Create an infrastructure diagram in 3 minutes using diagrams
Create a function in Python
Create a dictionary in Python
Create an exe file that works in a Windows environment without Python with PyInstaller
Create a local scope in Python without polluting the namespace
Try building a neural network in Python without using a library
How to create an instance of a particular class from dict using __new__ () in python
Create a python GUI using tkinter
Create a DI Container in Python
Mixed normal distribution implementation in python
Create a binary file in Python
Create Gmail in Python without API
Create a Kubernetes Operator in Python
Create a random string in Python
Create an instance of a predefined class from a string in Python
How to create a heatmap with an arbitrary domain in Python
Create a simple GUI app in Python
Create a survival prediction model for Kaggle Titanic passengers without using Python
Create a JSON object mapper in Python
[Python] Create a Batch environment using AWS-CDK
Scraping a website using JavaScript in Python
[GPS] Create a kml file in Python
Draw a tree in Python 3 using graphviz
Create a record with attachments in KINTONE using the Python requests module
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
Create a Python image in Django without a dummy image file and test the image upload
A complete guidebook to using pyenv, pip and python in an offline environment
[Hyperledger Iroha] Create an account using Python library
Create a Vim + Python test environment in 1 minute
Create an executable file in a scripting language
I want to create a window in Python
How to create a JSON file in Python
Create a virtual environment with conda in Python
Create a web map using Python and GDAL
View drug reviews using a list in Python
Create an image with characters in python (Japanese)
Create a simple momentum investment model in Python
Make a joyplot-like plot of R in python
Create a new page in confluence with Python
Create a datetime object from a string in Python (Python 3.3)
Create a package containing global commands in Python
Create a Mac app using py2app and Python3! !!
Create 3D scatter plot with SciPy + matplotlib (Python)
Create a loop antenna pattern in Python in KiCad
Insert an object inside a string in Python
Solve simultaneous equations in an instant using Python
[Docker] Create a jupyterLab (python) environment in 3 minutes!
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
[LINE Messaging API] Create a rich menu in Python
Create an image file using PIL (Python Imaging Library).
[Python] Create a ValueObject with a complete constructor using dataclasses
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create your first GDSII file in Python using gdspy