-
matplotlib设置图片边缘距离(left=0.1, right=0.9, top=0.9, bottom=0.1)
2019-09-18 17:18:52import matplotlib.pyplot as plt plt.plot(whatever) plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)import matplotlib.pyplot as plt
plt.plot(whatever)
plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1) -
matplotlib - spines 设置
2021-02-07 15:25:51matplotlib spines 设置简介隐藏图脊设置图脊位置参考 简介 在 Matplotlib 中,Spine 指绘图区四周的边界线(这里姑且将其翻译为图脊),如下图所示。 使用 Axes.spines 更改图脊的属性。实现诸如删除顶部和右侧的...简介
在 Matplotlib 中,Spine 指绘图区四周的边界线(这里姑且将其翻译为图脊),如下图所示。
使用
Axes.spines
更改图脊的属性。实现诸如删除顶部和右侧的图脊,或者将左侧图脊移动原点等功能。Axes.spines
属性是一个字典对象,通过right
,left
,top
,bottom
键可以访问各个方位的图脊。隐藏图脊
使用
set_color
将图脊的颜色设置为None
,可以隐藏图脊,例如,绘制一个简单的线性图:import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 2, 100) fig, ax = plt.subplots() ax.plot(x, x, label="linear") plt.xlabel('x label') plt.ylabel('y label') plt.title("Simple Plot") plt.legend() plt.show()
下面移除右侧和上面的图脊:import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 2, 100) fig, ax = plt.subplots() ax.plot(x, x, label="linear") ax.spines['right'].set_color('none') // 隐藏右侧图脊 ax.spines['top'].set_color('none') // 隐藏上面图脊 plt.xlabel('x label') plt.ylabel('y label') plt.title("Simple Plot") plt.legend() plt.show()
设置图脊位置
使用
set_position()
方法设置图脊位置,其参数为 tuple 类型 ,包含两个需要设置的值(position_type, amount)
。一个是位置类型:- ‘outward’,将图脊向图形区域外移动;
- ‘axes’,将图脊放在指定的 Axes 坐标(0到1之间);
- ‘data’,将图脊放在指定的数据坐标位置。
另外还有两个特殊值:
- ‘center’ 表示 (‘axes’, 0.5)
- ‘zero’ 表示 (‘data’, 0.0)
下面我们绘制一个二次曲线图:
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-1, 3, 100) y = (x - 1) ** 2 fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['right'].set_color('none') # 隐藏右侧图脊 ax.spines['top'].set_color('none') # 隐藏上面图脊 # plot the function plt.plot(x, y, 'r') # show the plot plt.show()
然后我们将左侧图脊移到 0 位置:
import matplotlib.pyplot as plt import numpy as np x = np.linspace(-1, 3, 100) y = (x - 1) ** 2 fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['left'].set_position('zero') # 额外添加行 ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # plot the function plt.plot(x, y, 'r') # show the plot plt.show()
参考
-
matplotlib坐标轴设置-2
2020-07-08 10:21:32坐标轴位置挪动 获取轴边框 ...设置x ,y 轴位置:如ax.spines['bottom'].set_position(('data', y0)),参数为 元组 ax.spines['bottom'].set_position(('data', y0)) # x轴与y轴为y0的位置相交 ax坐标轴位置挪动
-
获取轴边框
ax = plt.gca()
-
删除右边、上边的边框
ax.spines['right'].set_color('none') ax.spines['top'].set_color('none')
-
设置x ,y 轴位置:如
ax.spines['bottom'].set_position(('data', y0))
,参数为 元组ax.spines['bottom'].set_position(('data', y0)) # x轴与y轴为y0的位置相交 ax.spines['left'].set_position(('data', x0)) # y轴与x轴为x0的位置相交 #两者合一表示x,y轴交于(x0,y0)点
-
完整代码
import matplotlib.pyplot as plt import numpy as np x=np.linspace(-1,1,50) y1 = x**2 y2 = x**3 plt.figure(num=4) # figure对象名称、尺寸设置 plt.plot(x,y2) plt.plot(x,y1,color='red',linewidth=2.0,linestyle='--') #获取轴边框 ax = plt.gca() print(ax) # ax.xaxis.tick_bottom() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.spines['bottom'].set_position(('data', 0)) ax.spines['left'].set_position(('data', 0))
-
-
Matplotlib之设置x,y坐标轴的位置
2019-07-19 12:44:59先将显示的坐标图的上边框和右边框去掉,即设置它们的显示方式为不显示: ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') 注:spines译为‘脊’,也就是坐标图中的边框。 将坐标图的...- 先将显示的坐标图的上边框和右边框去掉,即设置它们的显示方式为不显示:
ax.spines['right'].set_color('none') ax.spines['top'].set_color('none')
注:spines译为‘脊’,也就是坐标图中的边框。
- 将坐标图的下边框和左边框作为坐标系的x轴和y轴,并调整坐标轴的位置:
ax.spines['bottom'].set_position(('data',0)) #data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置 ax.spines['left'].set_position(('axes',0.5)) #axes表示以百分比的形式设置轴的位置,即将y轴绑定在x轴50%的位置,也就是x轴的中点
注:设置坐标轴的位置时,‘data’表示通过值来设置坐标轴的位置, ax.spines['bottom'].set_position(('data',0))表示将x轴设置在y=0处。'axes'表示以百分比的形式设置轴的位置,ax.spines['bottom'].set_position(('axes',0.3))表示将x轴设置在y轴范围的30%处。除了‘data’、‘axes’属性,还有一个‘outward’属性可以来设置坐标轴的位置,这个属性我还没有用过。
例子:
import matplotlib.pyplot as plt from numpy import * x=linspace(-2,2) y=2*x+1 plt.xlim(-2,2) plt.ylim(-3,5) ax=plt.gca() #gca:get current axis得到当前轴 #设置图片的右边框和上边框为不显示 ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') #挪动x,y轴的位置,也就是图片下边框和左边框的位置 ax.spines['bottom'].set_position(('data',0)) #data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置 ax.spines['left'].set_position(('axes',0.5)) #axes表示以百分比的形式设置轴的位置,即将y轴绑定在x轴50%的位置,也就是x轴的中点 plt.plot(x,y) plt.show() #显示
运行结果:
-
ax.spines——matplotlib坐标轴设置
2018-10-11 17:32:03通常软件绘图,包括 matlab、python 的 ...在matplotlib的图中,默认有四个轴,两个横轴和两个竖轴,可以通过ax = plt.gca()方法获取,gca是‘get current axes’的缩写,获取图像的轴,总共有四个轴top、bottom、... -
matplotlib绘图(四)布局设置
2021-01-30 16:07:34import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec """ 第一种方法,plt.subplots()方法,直接指定多少行...fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1, wspace=0.5, -
python可视化直方图的x轴参数设置_Matplotlib/matplotlib可视化柱状图.md at master · kmmao/Matplotlib ...
2021-03-06 00:04:09import matplotlib.pyplot as plt柱状图应用于比较分类变量的数值,例如可以用于展示衣服裤子鞋子等商品的销售量。主要参数介绍:bar(left, height, width=0.8, bottom=None, **kwargs)left为和分类数量一致的数值... -
python画图,使用matplotlib和seaborn来设置图形的字体大小,坐标轴的线宽,风格,取值范围
2020-06-05 19:30:471. matplotlib 样式的设计 1.1 设置坐标轴的线框 ...ax.spines['bottom'].set_linewidth(2);###设置底部坐标轴的粗细 ax.spines['left'].set_linewidth(2);####设置左边坐标轴的粗细 ax.spines['right'].set_line -
matplotlib画直线
2016-12-26 16:23:46使用matplotlib画两条直线:Code :from matplotlib.lines import Line2D import matplotlib.pyplot as plt ...# 设置x,y值域 ax.set_xlim(left=0, right=20) ax.set_ylim(bottom=0, top=10) # 两条line的数据 -
python设置x轴宽度_python – Matplotlib:如何指定x-label边界框的宽度
2020-12-10 10:14:19我正在尝试在MatPlotLib中创建堆叠条形图,在顶部和底部有两个不同的x标签.上面的一个应该有一个边界框,宽度与条本身相同.情节不太正确这是我创建标签的方式:plt.tick_params(axis="both", left=False, bottom=False... -
柱状图怎么设置柱的宽度_?Matplotlib入门-6-plt.bar( )绘制柱状图
2021-01-07 01:09:13在本篇文章中,我们将接触一个新的绘图函数plt.bar( ),它用于柱状图的绘制。...(1)基本参数讲解matplotlib.pyplot.bar(x, height, width=0.8, bottom=None,color)import matplotlib.pylab as plt plt.bar... -
数据分析可视化-matplotlib
2021-02-01 21:36:59数据分析可视化-matplotlib 1、figure 属性:color,linewidth,linestyle 2、设置坐标轴 plt.xlim设置坐标轴范围 plt.xlabel设置坐标轴名称 plt.xticks设置x轴刻度 使用ax=plt.gca获取当前坐标轴信息. 使用ax.spines... -
Matplotlib 注释(Annotate)
2021-01-13 09:39:15import matplotlib.pyplot as plt # 创建坐标系 ax = plt.subplot(1, 1, 1) # 设置坐标轴位置 ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.spines['bottom'].set_position(('... -
入门matplotlib—坐标轴
2021-02-05 19:24:22import matplotlib.pyplot as plt # 遇到数据中有中文的时候,一定要先设置中文字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文 x,y = plt.subplots(1,1) y.spines['left'].set_color('r') y.... -
Python matplotlib 出现底部显示不全
2020-03-30 17:56:27原因:matplotlib新版本,subplot.bottom默认为0.1 但是电脑分辨率过低时,这个默认的0.1,导致绘图窗口不足,底部便被剪切了。 解决:设置subplot.bottom为0.15 plt.gcf().subplots_adjust(bottom=0.15) 绘制... -
利用matplotlib实现根据实时数据动态更新图形
2020-12-23 07:06:14我就废话不多说了,直接上代码吧! from time import sleep from threading importThread ...plt.subplots_adjust(bottom=0.2) #实验数据 range_start, range_end, range_step =0,1,0.005 t = np.arange(range_star -
matplotlib绘制热力图
2018-08-29 15:49:22以在sklearn的svm为例 ...plt.subplots_adjust(left=.2, right=0.95, bottom=0.15, top=0.95) #设置标注前后左右的距离 plt.imshow(scores, interpolation='nearest', cmap=plt.cm.hot, norm=Mid... -
Matplotlib 绘图实用大全
2020-12-01 19:19:36要想画出来的图有些逼格,首先应该进行如下设置 plt.rcParams['font.sans-serif']=['SimHei'] #画图时显示中文字体 plt.rcParams['axes.unicode_minus'] = False #防止因修改成中文字符,导致某些 unicode 字符不能... -
matplotlib绘制直方图
2020-12-17 13:30:04曲线图的使用axes子图中的plot函数。...该参数可为每一个数据点设置权重 cumulative 是否需要计算累计频数或频率 bottom 可以为直方图的每个条形添加基准线,默认为0 histtype 指定直方图的类型,默认为ba -
matplotlib绘制柱状图
2020-07-28 13:05:58plt.bar(x, height, color,edgecolor,width=0.8,align='center',bottom=None) 必选参数: x,表示横坐标刻度值,可以是array、list等 height,表示每个柱子的高度,可以是array、list等 可选参数: color:每个... -
基于matplotlib的数据可视化
2021-02-24 21:58:39坐标轴设置主要有坐标轴范围、坐标轴名称、坐标轴刻度、十字坐标等坐标轴的设置必须先获得坐标轴,再对坐标轴进行操作获取坐标轴的方法:ax=plt.gca()gca-getcurrentaxes注意,坐标轴共有四个top、bottom、left、... -
如何提升matplotlib画图速度
2021-03-02 09:37:421, bottom=0, right=1, left=0, hspace=0, wspace=0) plt.margins(0, 0) # 调整画布留白 print('画图时间', time.time() - begin) def _add_background(self, info): ""... -
使用matplotlib.pyplot绘制论文图片
2019-02-22 10:26:08import numpy as np import matplotlib.pyplot as plt plt.figure(figsize=(60, 25)) plt.subplot(241) ax = plt.gca() #gca ‘get ...== 设置有边框和头部边框颜色为空right、top、bottom、left ax.spines[‘r... -
matplotlib正弦余弦曲线的完善
2019-09-10 22:21:59去除上边和右边的坐标边框,指定data,设置的bottom(也就是指定的x轴)绑定到y轴的0这个点上 #get current axis 获得坐标轴对象 ax = plt.gca() #去除上边 和 右边的 坐标边框 ax.spines['right'].set_color('... -
-
matplotlib词云和饼状图的标注问题
2019-04-24 16:08:07import matplotlib.pyplot as plt import numpy as np import sys from PyQt5.QtGui import * from PyQt5.QtWidgets import * import jieba from os import path from PIL import Image from wordcloud ... -
c++ 显示三维散点图_Pythonmatplotlib 学术散点图完善
2020-11-21 14:41:3701. 引言上期的推文Python-matplotlib 学术型散点图绘制推出后,很多小伙伴比较喜欢,希望能够推出更多的类似绘制教程推文,当然,也提出了一些问题,比如学术图表的字体设置、相关性散点图绘制线的完善,以及多图... -
Matplotlib:axes脊柱(坐标轴)
2019-09-24 20:29:33设置axes脊柱(坐标系) 属性列表 (1)去掉脊柱(坐标系) ax.spines[‘top’].set_visible(False) #去掉上边框 ax.spines[‘bottom’].set_visible(False) #去掉下边框 ax.spines[‘left’].set_visible(False) #去掉... -
数据可视化Matplotlib使用5-改变坐标轴的默认显示方式
2021-03-08 14:24:02import matplotlib.pyplot as plt y = range(0,14,2) x = [-3,-2,-1,0,1,2,3] # # 获得当前图表的图像 # ax = plt.gca() # # 设置图型的包围线 # ax.spines['right'].set_color('none') # ax.spines['top'].set_...