matplotlib 可视化 —— 移动坐标轴(中心位置)
通常软件绘图,包括 matlab、python 的 matplotlib,默认都是将坐标轴置于画布(figure)的最下侧(x 轴),最左侧(y 轴),也即将坐标原点置于左下角。而我们自己理解数学,以及手动绘图时,都会将坐标轴置于中心的位置。
1. 导入相关的包
import numpy as np
import matplotlib.pyplot as plt
2. 获取 figure 和 axis
fig = plt.figure(figsize=(4, 4))
ax = fig.add_subplot(111)
plt.show()
3. 隐藏上边和右边
上下左右,四个边属于当前轴对象(axis);
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
4. 移动另外两个轴
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data', 0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data', 0))
5. 填充数据
theta = np.arange(0, 2*np.pi, 2*np.pi/100)
ax.plot(np.cos(theta), np.sin(theta))
plt.show()
7. 其他设置
plt.style.use('ggplot')
ax.set_xticks([-1.2, 1.2])
ax.set_yticks([-1.2, 1.2])
完整代码:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4, 4))
ax = fig.add_subplot(111)
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data', 0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data', 0))
theta = np.arange(0, 2*np.pi, 2*np.pi/100)
ax.plot(np.cos(theta), np.sin(theta))
plt.style.use('ggplot')
ax.set_xticks([-1.2, 1.2])
ax.set_yticks([-1.2, 1.2])
plt.show()
matplotlib 可视化 —— 移动坐标轴(中心位置)的更多相关文章
- SciKit-Learn 使用matplotlib可视化数据
章节 SciKit-Learn 加载数据集 SciKit-Learn 数据集基本信息 SciKit-Learn 使用matplotlib可视化数据 SciKit-Learn 可视化数据:主成分分析(P ...
- iOS10 UI教程视图的中心位置
iOS10 UI教程视图的中心位置 center表示的是视图的中心位置属性,这个属性在相对的UI层次结构上工作,和frame类似.center属性是一个在父视图上定义视图的位置的简便方法.center ...
- 国外大神制作的一个很棒的matplotlib 可视化教程
国外大神制作的一个很棒的matplotlib 可视化教程 参考:https://www.machinelearningplus.com/plots/top-50-matplotlib-visualiz ...
- matplotlib可视化之如何给图形添加数据标签?
当我们获取完数据之后,一般来说数据可视化呈现的最基础图形就是:柱状图.水平条形图.折线图等等,在python的matplotlib库中分别可用bar.barh.plot函数来构建它们,再使用xtick ...
- pyhton matplotlib可视化图像基础(二维函数图、柱状图、饼图、直方图以及折线图)
//2019.07.22pyhton中matplotlib模块的应用pyhton中matplotlib是可视化图像库的第三方库,它可以实现图像的可视化,输出不同形式的图形1.可视化图形的输出和展示需要 ...
- Python数据分析matplotlib可视化之绘图
Matplotlib是一个基于python的2D画图库,能够用python脚本方便的画出折线图,直方图,功率谱图,散点图等常用图表,而且语法简单. Python中通过matplotlib模块的pypl ...
- matplotlib 可视化 —— 定制 matplotlib
1. matplotlibrc 文件 matplotlib使用matplotlibrc [matplotlib resource configurations] 配置文件来自定义各种属性,我们称之为 ...
- matplotlib可视化最全指南
1. 折线图:plt.plot 设置数据:plt.plot(x,y),单列数据传入默认y轴,此时x轴数据默认从0逐渐对应递增 设置颜色:plt.plot(x,y,color/c=" &quo ...
- python库之matplotlib学习---关于坐标轴
首先定·定义x, y创建一个figure import numpy as np import matplotlib.pyplot as plt x = np.linspace(-1, 1, 10) y ...
随机推荐
- SQL SERVER-NULL
SQL SERVER判断NULL的函数 ISNULL().NVL().IFNULL() 和 COALESCE() 函数 来自为知笔记(Wiz)
- maven规定的目录
Maven规定的目录结构 若要使用Maven,那么项目的目录结构必须符合Maven的规范 ,如写一个使用Spring的Web项目就需要引入大量的jar包.一个项目Jar包的数量之多往往让我们瞠目结舌, ...
- Android 中模仿 Twitter 实现 Toolbar Indicator
项目地址:https://github.com/nekocode/ToolbarIndicator
- HDU 1232 - 并查集 解题报告
畅通project Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- POJ 题目2774 Long Long Message(后缀数组,求最长公共子串长度)
Long Long Message Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 23696 Accepted: 97 ...
- Java面试中常问的数据库方面问题
MySQL 为什么用自增列作为主键 如果我们定义了主键(PRIMARY KEY),那么InnoDB会选择主键作为聚集索引.如果没有显式定义主键,则InnoDB会选择第一个不包含有NULL值的唯一索引作 ...
- LeetCode OJ 215. Kth Largest Element in an Array 堆排序求解
题目链接:https://leetcode.com/problems/kth-largest-element-in-an-array/ 215. Kth Largest Element in an A ...
- leetcode 题解 || Longest Common Prefix 问题
problem: Write a function to find the longest common prefix string amongst an array of strings. 寻找 0 ...
- sicily 1002 Anti-prime Sequences
debug了好久..各种犯错..按照某个学长的思路,终于AC了.. #include <iostream> #include <cstring> using namespace ...
- @RequestMapping[转]
转自 http://www.cnblogs.com/qq78292959/p/3760560.html#undefined 引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST. ...