美文网首页
matplotlib_basic_设置坐标轴1

matplotlib_basic_设置坐标轴1

作者: Ledestin | 来源:发表于2017-05-18 00:10 被阅读61次

本文主要介绍在 matplotlib 中如何设置坐标轴的范围, 单位长度, 替代文字等等.


Demo.py

import matplotlib.pyplot as plt
import numpy as np

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

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

plt.xlim((-1, 2))#使用plt.xlim设置x坐标轴范围:(-1, 2)
plt.ylim((-2, 3))#使用plt.ylim设置y坐标轴范围:(-2, 3)

plt.xlabel('I am x')#使用plt.xlabel设置x坐标轴名称:’I am x’
plt.ylabel('I am y')#使用plt.ylabel设置y坐标轴名称:’I am y’
plt.show()

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

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

new_ticks = np.linspace(-1, 2, 5)#使用np.linspace定义范围以及个数:范围是(-1,2),个数是5
print new_ticks #使用print打印出新定义的范围
plt.xticks(new_ticks)#使用plt.xticks设置x轴刻度:范围是(-1,2),个数是5.
plt.yticks([-2, -1.8, -1, 1.22, 3],[r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$'])
#使用plt.yticks设置y轴刻度以及名称:刻度为[-2, -1.8, -1, 1.22, 3];
#对应刻度的名称为[‘really bad’,’bad’,’normal’,’good’, ‘really good’]
plt.show()

结果:

Paste_Image.png

[-1. -0.25 0.5 1.25 2. ]

Paste_Image.png

相关文章

  • matplotlib_basic_设置坐标轴1

    本文主要介绍在 matplotlib 中如何设置坐标轴的范围, 单位长度, 替代文字等等. Demo.py 结果:...

  • matplotlib_basic_设置坐标轴2

    本文介绍如何移动matplotlib 中 axis 坐标轴的位置,使用.spines设置边框:x轴,y轴;使用.s...

  • 莫烦Matplotlib基本使用

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

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

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

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

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

  • 2.2展示数据Matpoltlib

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

  • 图表坐标轴问题

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

  • Python画图&读写csv

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

  • Matplotlib模块-阶段二

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

  • Matplotlib的使用

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

网友评论

      本文标题:matplotlib_basic_设置坐标轴1

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