🤖
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

Was this helpful?

  1. Data Visualization
  2. Matplotlib

Any line and label

import pylab
import numpy as np

def draw_a_line(formula, x_range, label=''):  
    x = np.array(x_range)  
    y = eval(formula)
    pylab.plot(x, y, '-', label=label)

# draw -x^2
x = np.linspace(-5, 1.5)
y = np.negative(np.power(x, 2))
pylab.plot(x, y, '-k', label = r'$y = -x^2$')

# draw two lines
draw_a_line('2*x + 1', range(-5, 3))
draw_a_line('(2/5)*(x + 1/5) - 1/25', range(-5, 3))

# draw a point
pylab.plot(-1, -1, 'bo', label = r'$y^\prime(1) = -2$')
pylab.plot(-0.2, -1/25, 'ro', label = r'$y^\prime(-\frac{1}{2}) = -\frac{1}{25}$')

pylab.legend(loc='lower right')
pylab.show()
PreviousSimple line and pointNextAnnotation in reality

Last updated 6 years ago

Was this helpful?