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

python- plot 画图-plot and bar

程序员文章站 2022-07-13 11:02:24
...
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
x = [0, 1, 2, 3, 4]
y = [0, 2, 4, 6, 8]

# resize graph
plt.figure(figsize = (5,3), dpi= 200)
plt.plot(x, y, label = 'y = 2x', color = 'red', 
         linewidth = 2, marker = '.', linestyle = '--',
         markersize = 10, markeredgecolor = 'blue')

x2 = np.arange(0, 4.5, 0.5)
plt.plot(x2, x2 ** 2, 'b', label = 'y = x^2')
plt.title('our graph')
plt.xlabel('x Axis')
plt.ylabel('y Axis')

plt.xticks([0, 1, 2, 3, 4])
plt.yticks([0, 2, 4, 6, 8, 10, 12])
plt.savefig('mygraph.png', dpi = 300) # save fig

plt.legend()
plt.show()

python- plot 画图-plot and bar

labels = ['A', 'B', 'C']
values = [1, 4, 2]

bars = plt.bar(labels, values)
bars[0].set_hatch('/')
bars[1].set_hatch('o')
bars[2].set_hatch('*')

plt.figure(figsize = (6, 4))
plt.show()

python- plot 画图-plot and bar

相关标签: Python