python
崔小菜
人生30迷茫中前行
展开
-
绘制饼图
import matplotlib.pyplot as pltplt.figure(1, figsize=(6, 6))ax = plt.axes([0.1, 0.1, 0.8, 0.8])# 饼图按逆时针顺序画出labels = 'Spring', 'Summer', 'Autumn', 'Winter'# 饼图每部分定义为x/sum(x),或者x if sum(x) <= 1翻译 2017-10-23 21:33:29 · 508 阅读 · 0 评论 -
绘制带填充区域的图表
import matplotlib.pyplot as pltimport numpy as npx = np.arange(0.0, 2, 0.01)y1 = np.sin(2 * np.pi * x)y2 = 1.2 * np.sin(4 * np.pi * x)fig = plt.figure()ax = plt.gca()ax.plot(x, y1, x, y2, c翻译 2017-10-23 21:35:53 · 537 阅读 · 0 评论 -
定义图表类型——柱状图、线形图和堆积柱状图
from matplotlib import pyplot as pltx = [1, 2, 3, 4]y = [5, 4, 3, 2]dataset = [113, 115, 119, 121, 124, 124, 125, 126, 126, 126, 127, 127, 128, 129, 130, 130, 131,翻译 2017-10-23 21:15:08 · 2443 阅读 · 0 评论 -
简单的正弦图和余弦图
from matplotlib import pyplot as pltimport numpy as np'''numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) retstep=True, return (samples, st翻译 2017-10-23 21:20:47 · 4550 阅读 · 0 评论 -
设置坐标轴长度和范围
from matplotlib import pyplot as plt# axis()返回坐标轴的默认值(0.0, 1.0, 0.0, 1.0),(xmin, xmax, ymin, ymax)plt.axis()# 设置x轴和y轴的值ax_values = [-1, 1, -10, 10]plt.axis(ax_values)# plt.autoscale(),该方法会计算坐翻译 2017-10-23 21:22:55 · 8641 阅读 · 0 评论 -
设置图表的线型、属性和格式化字符串
from matplotlib import pyplot as pltx = [1, 3, 5, 7, 9]y = [2, 4, 6, 8, 10]'''# 改变线的属性# 第一种方式,向方法传入关键字参数来指定线型plt.plot(x, y, linewidth=15)''''''# 第二种方式,对plot()方法调用返回的线条实例(matplotlib.lines.L翻译 2017-10-23 21:24:53 · 371 阅读 · 0 评论 -
设置刻度、刻度标签和网格
from matplotlib import pyplot as pltimport matplotlib as mplimport numpy as npimport datetime'''# 返回当前显示图形的轴axisax = plt.gca()# 设置紧凑视图# nbins设置坐标轴一共平均分为几份,也可以显式的指定坐标轴,通过面向对象的方式或pyplot的方式# a翻译 2017-10-23 21:26:00 · 1205 阅读 · 0 评论 -
添加图例和注解
from matplotlib import pyplot as pltimport numpy as npx1 = np.random.normal(30, 3, 100)x2 = np.random.normal(20, 2, 100)x3 = np.random.normal(10, 3, 100)# 如果不想在图例中显示标签,可将标签设置为_nolegend_。plt.pl翻译 2017-10-23 21:27:54 · 3211 阅读 · 0 评论 -
移动轴线到图中央
from matplotlib import pyplot as pltimport numpy as npx = np.linspace(-np.pi, np.pi, 500, endpoint=True)y = np.sin(x)plt.plot(x, y)# 移动轴线到图中央ax = plt.gca()# 隐藏上和右两条脊柱,将其设置为无色ax.spines['rig翻译 2017-10-23 21:29:32 · 301 阅读 · 0 评论 -
绘制直方图
from matplotlib import pyplot as pltimport numpy as npmu = 100sigma = 15x = np.random.normal(mu, sigma, 10000)ax = plt.gca()# 调用plt.hist()创建直方图'''bins:可以是一个bin数量的整数值,也可以是表示bin的一个序列。默认值为10r翻译 2017-10-23 21:30:29 · 397 阅读 · 0 评论 -
绘制误差条形图
import matplotlib.pyplot as pltimport numpy as npx = np.arange(2, 10, 1)y = np.log(x)xe = 0.1 * np.abs(np.random.rand(len(y)))# 创建误差条形图'''left:x轴的位置序列height:y轴的数值序列,即柱形图的高度xerr/yerr:用于在柱状翻译 2017-10-23 21:32:30 · 4484 阅读 · 0 评论 -
绘制带彩色标记的散点图
import matplotlib.pyplot as pltimport numpy as npx = np.random.rand(1000)# 不相关数据y1 = np.random.rand(len(x))# 强正相关数据y2 = 1.2 + np.exp(x)ax1 = plt.subplot(121)# alpha:透明度# marker:设置点状标记plt.翻译 2017-10-23 21:39:42 · 1294 阅读 · 0 评论