🤖
Artificial Intelligence for Idiot
  • Introduction
  • What is Machine Learning
  • Python Basics
    • Random Number
  • Data Manipulation
    • Numpy
    • Pandas
  • Data Visualization
    • Matplotlib
      • Simple drawing
      • Simple line and point
      • Any line and label
      • Annotation in reality
  • Dataset Searching
  • Keras
    • Data preparation
    • Build the simplest model
  • Robot
    • Speech to Text
Powered by GitBook
On this page
  • Sine wave
  • Subplot

Was this helpful?

  1. Data Visualization
  2. Matplotlib

Simple drawing

PreviousMatplotlibNextSimple line and point

Last updated 4 years ago

Was this helpful?

Sine wave

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 360)
y = np.sin(np.radians(x))

plt.plot(x, y)
plt.show()

Subplot

import numpy as np
import matplotlib.pyplot as plt

fig, figure_parts = plt.subplots(3, 2)
fig.suptitle('yingshaoxo: This is life')

degree = 0

for index in range(3 * 2):
    random_num = np.random.randint(180, 360, size=1)[0]
    
    x = np.arange(degree, degree + random_num) 
    y = np.sin(np.radians(x))
    degree += random_num
    
    ax = figure_parts[index//2][index%2]
    ax.set_xlabel(str(index))
    ax.plot(x, y)
    
fig.set_size_inches(19, 12)
plt.savefig('this is life.png', dpi=100, bbox_inches='tight' )
plt.show()