欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Matplotlib绘制直线图

程序员文章站 2022-07-14 10:00:04
...

Code 1

import matplotlib.pyplot as plt

x = [3, 4]
y = [6, 9]

plt.plot(x, y, linewidth=6)

plt.show()

Matplotlib绘制直线图

Code 2

import numpy as np

import matplotlib.pyplot as plt

x = np.linspace(-1, 1, 50)

y = 3*x + 10

plt.figure()

plt.plot(x, y)

plt.show()

Matplotlib绘制直线图

Code 3

import numpy as np

import matplotlib.pyplot as plt

x = np.linspace(-3, 3, 50)

y1 = 3*x + 10

y2 = x**2

plt.figure()

plt.plot(x, y1)

plt.show()

plt.figure(num=4, figsize=(6, 8))

plt.plot(x, y2)

plt.plot(x, y1, color='red', linewidth='1.0', linestyle='--')

plt.show()

Matplotlib绘制直线图

Code 4

import numpy as np

import matplotlib.pyplot as plt

# font_set = FontProperties(fname=r"C:/Windows/Fons/simsun.ttc", size=15)

x = np.linspace(-3, 3, 50)

y1 = 2*x + 1

y2 = x**2

plt.figure()

plt.plot(x, y1)

plt.show()

plt.figure(num=3, figsize=(8, 5))

plt.plot(x, y2)

plt.plot(x, y1, color='red', linewidth='1.0', linestyle='--')

plt.xlim((-1, 2))

plt.ylim((-2, 3))

new_ticks = np.linspace(-1, 2, 5)

print(new_ticks)

plt.xticks(new_ticks)

plt.yticks([-2, -1.8, -1, 1.22, 3, ], [r'really bad', r'bad', r'normal', r'good', r'really good'])

plt.show()

Matplotlib绘制直线图