美文网首页
坐标轴设置

坐标轴设置

作者: 地平线上的背影 | 来源:发表于2019-02-14 11:37 被阅读0次

为更方便展示和对比数据,我们需要对坐标轴做出一定的设置。

1. 准备数据

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3, 3, 50)
y1 = 2*x + 1
y2 = x**2

2. 绘制图像

plt.figure()
plt.plot(x, y2)
# plot the second curve in this figure with certain parameters
plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')

注:plt.plot(x, y, color, linewidth, linestyle),存在多种参数

3. 设置坐标轴标签和显示区域

# set x limits
plt.xlim((-1, 2))
plt.ylim((-2, 3))
plt.xlabel('I am x')
plt.ylabel('I am y')

注:
1.plt.xlim((tuple)):(tuple)为坐标轴的显示区域,同样可设置 y 轴限制
plt.xlabel('text'):设置坐标轴的Label为 ' text ',同样可设置 y 轴标签

4. 自定义坐标轴

# set new sticks
new_ticks = np.linspace(-1, 2, 5)
print(new_ticks)
plt.xticks(new_ticks)
# set tick labels
plt.yticks([-2, -1.8, -1, 1.22, 3],
           [r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])

注:
1.plt.xticks(array):自定义Array使坐标轴仅显示Array指定刻度
2.plt.yticks([array-1],[array-2]):指定坐标轴以Array-2显示Array-1指定刻度

5. 自定义显示框

5.1 隐藏不需要的显示框边界
# gca = 'get current axis'
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
5.2 选定边界为坐标轴并设定位置
ax.xaxis.set_ticks_position('bottom')
# ACCEPTS: [ 'top' | 'bottom' | 'both' | 'default' | 'none' ]

ax.spines['bottom'].set_position(('data', 0))
# the 1st is in 'outward' | 'axes' | 'data'
# axes: percentage of y axis
# data: depend on y data

ax.yaxis.set_ticks_position('left')
# ACCEPTS: [ 'left' | 'right' | 'both' | 'default' | 'none' ]

ax.spines['left'].set_position(('data',0))
plt.show()

相关文章

  • 莫烦Matplotlib基本使用

    设置坐标轴 移动坐标轴 关于legend图例 关于annotation标注 设置坐标轴 移动坐标轴 关于legen...

  • matplotlib 画图的相关设置:坐标轴刻度字体、大小等

    导入包 设置坐标轴范围 设置坐标轴名称、字体、大小 设置坐标轴刻度、字体、大小 标题、字体、大小 图例、字体、大小...

  • Python画图&读写csv

    设置字体 设置图例 设置坐标轴的范围和刻度 设置坐标轴的精度 Python读写csv文件 matplotlib在图...

  • Matplotlib模块-阶段二

    设置图例 设置注解 设置坐标轴可见度 散点图 柱状图 等高线 设置图例 设置注解 设置坐标轴可见度 散点图 简略散...

  • Matplotlib的使用

    安装 安装numpy 安装matplotlib 基础 设置坐标轴 plt.xlim设置x坐标轴范围plt.ylim...

  • 可视化学习笔记(六):ggplot2:坐标轴

    1、坐标轴设置 1.1 坐标轴转换 使用coord_flip()函数来将坐标轴翻转 当反转坐标轴后各项排列顺序发生...

  • 图表坐标轴问题

    1.将坐标轴设为万为单位:“设置坐标轴格式”-坐标轴选项里,显示单位改为“10000”,这时候坐标轴会变成原来的数...

  • 2.2展示数据Matpoltlib

    1. 基本使用 基本用法 figure图像 设置坐标轴 调整坐标轴 图例legend 标注annotation 能...

  • echarts 坐标轴

    option = {xAxis : {}, // x轴设置yAxis : {}, // y轴设置} 坐标轴分割线...

  • 关于SAS中GTL出图坐标轴刻度的处理

    在SAS GTL出图中,我们通常会根据数据的实际范围来进行坐标轴刻度设置,如果不设置,坐标轴默认显示可能不会太美观...

网友评论

      本文标题:坐标轴设置

      本文链接:https://www.haomeiwen.com/subject/ufbseqtx.html