-
Matplotlib绘图代码
2019-08-01 10:44:29Matplotlib绘图时,除了必要的数据信息展示外,还会遇到其他各种外在的问题,such as“中文显示”、“负号显示”以及绘制出的“图片大小”等。以下放了个人绘图时所用的代码,并将部分有用链接一并附上。 import ...Matplotlib绘图时,除了必要的数据信息展示外,还会遇到其他各种外在的问题,such as“中文显示”、“负号显示”以及绘制出的“图片大小”等。以下放了个人绘图时所用的代码,并将部分有用链接一并附上。
import matplotlib import matplotlib.pyplot as plt matplotlib.style.use('ggplot') from pylab import * mpl.rcParams['font.sans-serif'] = ['SimHei'] #用来显示中文 mpl.rcParams['axes.unicode_minus']=False #用来显示负号 matplotlib.rcParams['figure.figsize'] = [5.4, 4] # for square canvas plt.rcParams['savefig.dpi'] = 140 #图片像素 plt.rcParams['figure.dpi'] = 130 #分辨率
-
python matplotlib 绘图操作
2019-11-23 23:15:27图例置于边框外 标题操作 标题位置 注释操作 注释字体 配色操作 饼图颜色 子图操作 子图间距 坐标操作 参考博文Python绘图总结(Matplotlib篇)之坐标轴及刻度 对数坐标轴 import numpy as n...文章目录
坐标操作
参考博文
Python绘图总结(Matplotlib篇)之坐标轴及刻度对数坐标轴
import numpy as np import matplotlib.pyplot as plt import scipy.stats as sts if __name__ == '__main__': a = 0.031 / 10000 + 0.0337 / 10000 print(0.0336 * 100 / np.sqrt(a)) # 1320.95 r = sts.lognorm.rvs(0.954, size=1000) c = plt.hist(r, bins=500) plt.show() # 双对数坐标下 fig, ax = plt.subplots() ax.set_xscale("log") ax.set_yscale("log") ax.set_adjustable("datalim") ax.plot(c[1][:-1], c[0], 'o') ax.set_xlim(1e-1, 1e6) ax.set_ylim(1e-2, 1e6) ax.grid() plt.draw() plt.show() # 半对数坐标 fig1, ax1 = plt.subplots() ax1.hist(r, bins=500) ax1.set_xscale("log") ax1.set_xlim(1e-1, 1e6) ax1.grid() plt.draw() plt.show()
效果如下
坐标刻度及其标记
python_matplotlib改变横坐标和纵坐标上的刻度(ticks)
font = {'family': 'arial', 'weight': 'normal', 'size': 14} ax1.set_xticks([1,2,3,4,5) ax1.set_xticklabels(x,font) ax1.set_yticks([0,0.2,0.4,0.6,0.8,1]) ax1.set_yticklabels([0,0.2,0.4,0.6,0.8,1],font)
横坐标值逆序显示
逆序前的代码和图
import matplotlib.pyplot as plt plt.figure() ax1 = plt.subplot(111) x_list = [1, 2, 3, 4, 5] y_list = [5, 10, 20, 40, 80] plt.sca(ax1) plt.title("Test 1") plt.xlabel("X") plt.ylabel("Y") plot1, = plt.plot(x_list, y_list, 'bo') plt.show()
逆序后的代码和图import matplotlib.pyplot as plt plt.figure() ax1 = plt.subplot(111) x_list = [1, 2, 3, 4, 5] y_list = [5, 10, 20, 40, 80] plt.sca(ax1) plt.title("Test 1") plt.xlabel("X") plt.ylabel("Y") plot1, = plt.plot(x_list, y_list, 'bo') plt.gca().invert_xaxis() # 就这句话 plt.show()
边框操作
隐藏边框
ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False)
图例操作
参考博文
matplotlib命令与格式:图例legend语法及设置图例置于边框外
ax.legend(loc='center left', bbox_to_anchor=(0.2, 1.12),ncol=3)
标题操作
标题位置
ax.set_title('AUC', font, x=0.5, y=1.05)
x,y可以控制标题的位置,但是记住要放在 font 后面,不然会报错.
SyntaxError: positional argument follows keyword argument
注释操作
matplotlib.axes.Axes.annotate
matplotlib命令与格式:标题(title),标注(annotate),文字说明(text)注释字体
ax.annotate('{}'.format(height), xy=(rect.get_x() + rect.get_width() / 2, height), xytext=(0, 3), # 3 points vertical offset textcoords="offset points", # 字体属性 size=12, family='arial', ha='center', va='bottom')
配色操作
饼图颜色
# 色系 浅灰色 #d8dcd6 天蓝色 #069af3 lightblue(#7bc8f6) blue with a hint of purple(#533cc6) # purple red(#990147) # dark royal blue(#02066f) royal(#0c1793) ax.plot(a,b,linestyle='dotted',linewidth=2.5,marker='o',color='#e377c2',label='CN') ax.plot(a,c,linestyle='dotted',linewidth=2.5,marker='v',color='#533cc6',label='RA') ax.plot(a,d,linestyle='solid',linewidth=2.5,marker='d',color='#7d7f7c',label='PA') ax.plot(a,e,linestyle='dashed',linewidth=2.5,marker='8',color='#01ff07',label='LP')
子图操作
子图间距
matplotlib.pyplot.subplots_adjust
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) ## 默认参数 left = 0.125 # the left side of the subplots of the figure right = 0.9 # the right side of the subplots of the figure bottom = 0.1 # the bottom of the subplots of the figure top = 0.9 # the top of the subplots of the figure wspace = 0.2 # the amount of width reserved for space between subplots, # expressed as a fraction of the average axis width hspace = 0.2 # the amount of height reserved for space between subplots, # expressed as a fraction of the average axis height
-
matplotlib绘图:调整坐标刻度朝内/外
2020-02-21 18:57:00import matplotlib.pyplot as plt X = np.linspace(-np.pi, np.pi, 256, endpoint = True) C, S = np.cos(X), np.sin(X) plt.rcParams['xtick.direction'] = 'inout' # in; out; inout plt.r...import numpy as np import matplotlib.pyplot as plt X = np.linspace(-np.pi, np.pi, 256, endpoint = True) C, S = np.cos(X), np.sin(X) plt.rcParams['xtick.direction'] = 'inout' # in; out; inout plt.rcParams['ytick.direction'] = 'inout' plt.plot(X,C) plt.plot(X,S) plt.show()
-
python matplotlib实现将图例放在图外
2020-09-17 13:04:17主要介绍了python matplotlib实现将图例放在图外,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 -
python使用matplotlib绘图使刻度线向内
2019-05-23 19:04:56刻度向外的程序 import numpy as np import matplotlib.pyplot as plt num = np.arange(10).reshape(2,5) ##print(num[0]) plt.plot(num[0],num[1]) plt.show() 结果: 刻度向内的程序 ...python使用matplotlib绘图时使刻度线向内
- 刻度向外的程序
import numpy as np import matplotlib.pyplot as plt num = np.arange(10).reshape(2,5) ##print(num[0]) plt.plot(num[0],num[1]) plt.show()
结果:
- 刻度向内的程序
import numpy as np import matplotlib.pyplot as plt num = np.arange(10).reshape(2,5) ##print(num[0]) plt.rcParams['xtick.direction'] = 'in'#将x周的刻度线方向设置向内 plt.rcParams['ytick.direction'] = 'in'#将y轴的刻度方向设置向内 plt.plot(num[0],num[1]) plt.show()
结果:
-
python中plot画图图例_Python matplotlib中绘图外的图例
2020-12-04 22:44:19经过多次尝试,这是我能想到的最好的:from matplotlib.lines import Line2Dfrom matplotlib.gridspec import GridSpecfrom enum import Enumclass Location(Enum):EastOutside = 1WestOutside = 2NorthOutside = 3... -
matplotlib 横坐标只显示整数_Python3.matplotlib绘图琢磨02
2020-11-20 13:03:16上一篇介绍了pandas的DataFrame对象直接调用plot方法绘制折线图,这篇进一步介绍几个matplotlib功能。背景现有一个名为df的DataFrame如下通过如下代码ax 绘制出需求图例显示出中文横坐标标签中WV-IR11为下标横纵坐标... -
matplotlib条形图|柱状图
2020-03-22 19:55:13条形图: #适用于不连续的数据 #正常绘图,条形图是竖着的,...单个条形图的绘制过程和折线图类似,除了绘图函数使用plt.bar()或者plt.barh()外,其他绘图过程使用的函数一样。 import matplotlib from matplotlib... -
python matplotlib如何将图例放在图外
2017-01-27 11:27:16如何将图例放在图外?以及如何在一幅图有多个子图的情况下,删除重复的图例?我用一个简单的例子说明一下。import pandas as pd import numpy as np import matplotlib.pyplot as pltfig = plt.figure(1) ax1 = fig.... -
python怎么放图片_python matplotlib实现将图例放在图外
2020-12-05 22:12:26如何将图例放在图外?以及如何在一幅图有多个子图的情况下,删除重复的图例?我用一个简单的例子说明一下。import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfig = plt.figure(1)ax1 = fig.add... -
Matplotlib外观和基本配置笔记
2019-10-01 02:43:08Matplotlib外观和基本配置笔记 title: matplotlib 外观和基本配置笔记 notebook: Python tags:matplotlib ...参考资料,如何使用matplotlib绘制出数据图形,参考另一篇matplotlib绘制多种图... -
Python3.matplotlib绘图琢磨02
2020-05-01 16:28:33显示中文、下标、坐标末端箭头;纵坐标刻度用百分比表示;绘制垂直于坐标轴的线;图例的外边框不显示 -
pyqt内嵌matplotlib_使用PyQt5嵌入matplotlib,实现根据界面输入数值更换显示的matplotlib图形...
2020-12-21 03:29:54使用的编程语言是python3.4, 界面设计软件是erics 6结合PyQt51、使用QT Designer实现UI 界面在eric 6 中,点击项目,新建一个项目,增加如下图的一些控件与布局,不相同都可以。除了 QVBoxLayout 垂直布局、... -
动态曲线图(linechart)--Matplotlib绘制
2020-09-04 08:18:00戳我 ->卧槽!当当网图书全场4折了!作者:宁海涛来源:DataCharm效果预览配上动感的音乐感觉就是不一样啊,要达到上述效果除了核心的Matplotlib绘图外,其他工具和上... -
pb自定义多曲线图_动态曲线图(linechart)--Matplotlib绘制
2020-11-28 10:44:54效果预览动态曲线图matplotlib制作https://www.zhihu.com/video/1243633139404333056配上动感的音乐感觉就是不一样啊,要达到上述效果除了核心的Matplotlib绘图外,其他工具和上篇推文宁俊骐:Hans Rosling Charts..... -
python 图例位置_python matplotlib实现将图例放在图外
2020-12-06 06:48:50如何将图例放在图外?以及如何在一幅图有多个子图的情况下,删除重复的图例?我用一个简单的例子说明一下。import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfig = plt.figure(1)ax1 = fig.add... -
python直方图只显示外框_Python 绘图,我只用 Matplotlib
2020-12-06 13:00:47原标题:Python 绘图,我只用 Matplotlib散点图散点图显示两组数据的值,如图1-1所示。每个点的坐标位置由变量的值决定,并由一组不连接的点完成,用于观察两种变量的相关性。例如,身高—体重、温度—维度。 图1-1 ... -
matplotlib基础绘图命令之bar的使用方法
2021-01-19 23:45:32在matplotlib中,bar命令用于绘制柱状图,基本用法如下在matplotlib中,bar命令用于绘制柱状图,基本用法如下在matplotlib中,bar命令用于绘制柱状图,基本用法如下在matplotlib中,bar命令用于绘制柱状图,基本用法... -
matplotlib
2020-08-23 12:45:00import matplotlib.pyplot as plt import numpy as np import matplotlib.pyplot as plt N=1000 x = np.random.randn(N) y1 = np.random.randn(N) plt.scatter(x,y1) plt.show() 散点图外观调整 颜色:c 透明度:... -
qlineseries绘制动态曲线_动态曲线图(linechart)--Matplotlib绘制
2021-01-08 02:38:35效果预览动态曲线图matplotlib制作https://www.zhihu.com/video/1243633139404333056配上动感的音乐感觉就是不一样啊,要达到上述效果除了核心的Matplotlib绘图外,其他工具和上篇推文宁俊骐:Hans Rosling Charts..... -
python画图图例放在曲线边_python matplotlib实现将图例放在图外
2020-12-04 11:01:45如何将图例放在图外?以及如何在一幅图有多个子图的情况下,删除重复的图例?我用一个简单的例子说明一下。import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfig = plt.figure(1)ax1 = fig.add... -
matplotlib-20 分块图
2020-08-18 10:30:02当对数据进行统计时,除了使用堆积图外,分块图也是一种不错的选择。与堆积图不同的是,分块图将数据并列放置,能更好的体现出数据的差异性。 并列柱状图 # -*- coding: UTF-8 -*- import numpy as np import ... -
解决Windows系统下python利用matplotlib绘图时中文乱码的问题
2016-12-26 16:48:53进入方法:控制面板-->外观和个性化-->字体,进入后的界面如下图所示: 第二步: 在这个文件夹中找到“黑体 常规”这个字体的文件,如下图: 注:如果你的电脑中没有这个文件,你也可以试着找到其他的中文字体...
收藏数
269
精华内容
107