文章目录

  • 坐标操作

    • 对数坐标轴
    • 坐标刻度及其标记
    • 横坐标值逆序显示
  • 边框操作
    • 隐藏边框
  • 图例操作
    • 图例置于边框外
  • 标题操作
    • 标题位置
  • 注释操作
    • 注释字体
  • 配色操作
    • 饼图颜色
  • 子图操作
    • 子图间距

坐标操作

参考博文
Python绘图总结(Matplotlib篇)之坐标轴及刻度

对数坐标轴

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stsif __name__ == '__main__':a = 0.031 / 10000 + 0.0337 / 10000print(0.0336 * 100 / np.sqrt(a))  # 1320.95r = 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 pltplt.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 pltplt.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 offsettextcoords="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

python matplotlib 绘图操作相关推荐

  1. Python+matplotlib绘图时显示中文的设置方法

    封面图片:<Python程序设计基础与应用>(ISBN:9787111606178),董付国,机械工业出版社 图书详情: =================== 在使用Python+mat ...

  2. Python Matplotlib绘图的正确打开方式

    Python Matplotlib绘图的正确打开方式 文章目录 Python Matplotlib绘图的正确打开方式 1.先搞懂fig.axes.axis `Figure` `Axes` `Axis` ...

  3. python画图显示不了中文_完美解决Python matplotlib绘图时汉字显示不正常的问题

    Matplotlib是一个很好的作图软件,但是python下默认不支持中文,所以需要做一些修改,方法如下: 1.在python安装目录的Lib目录下创建ch.py文件. 文件中代码为: 保存,以后通过 ...

  4. python 3d绘图 汉字_完美解决Python matplotlib绘图时汉字显示不正常的问题

    Matplotlib是一个很好的作图软件,但是python下默认不支持中文,所以需要做一些修改,方法如下: 1.在python安装目录的Lib目录下创建ch.py文件. 文件中代码为: 保存,以后通过 ...

  5. 科研论文绘图:ppt, word,latex,python matplotlib绘图 ,矢量图,高清图,放大不失真

    目录 1. 用PPT绘图,保存为高清图片,不推荐使用,方法链接 2. 用PPT绘图,保存为emf矢量图,适合插入word,方法链接 3. 用PPT画图,保存为eps文件,适合插入latex,方法链接 ...

  6. 解决 Python Matplotlib 绘图时不连续x轴自动补全的问题(xsticks)

    问题 发现一个奇怪的问题,记录一下: 用 Python Matplotlib绘图的时候,x轴为不连续的日期,但是画出来的图,对于不连续的部分x轴会自动补全,空出来的部分是没有值的.(x轴数据明明是明确 ...

  7. python绘制3d图-Python matplotlib绘图示例 - 绘制三维图形

    Python matplotlib模块是扩展的MATLAB的一个绘图工具库.它可以绘制各种图形,下面就学习了下Python中的matplotlib模块,如何绘制三维图形. 示例代码一: # codin ...

  8. 使用Python Matplotlib绘图并输出图像到文件中的实践

    在大数据及深度学习的背景下,随着卷积神经网络(CNN)的成功应用,图像识别能力好像唾手可得.最近实际工作中,却遇到了困难,难题是用于可学习的图像贫乏,很难形成用于学习的样本. 其实,也是有一定解决图像 ...

  9. python matplotlib绘图 axes和pyplot用法的区别是什么?子图subplot

    在matplotlib绘图过程中,经常会出现axes绘图和pyplot绘图这两种方法,但是如果不搞清楚它们的区别,往往会得不到你想要的图形.所谓axes绘图是指调用axes对象(坐标轴对象)去完成绘图 ...

  10. Python+matplotlib绘图使用Latex引擎渲染坐标轴刻度文本上标

    问题描述: 在使用matplotlib进行数据可视化或科学计算可视化时,有时候数值过大或过小,使得坐标轴刻度显示不方便,这时可以考虑使用科学计数法,例如把10000显示为,把0.00001显示为. 在 ...

最新文章

  1. Kube-Scheduler插件的自定义
  2. R语言回归模型协方差分析(Analysis of Covariance)
  3. 怎么体验华为鸿蒙系统,华为mate40升级鸿蒙系统体验_华为mate40升级鸿蒙系统使用感受...
  4. java 读取css文件_java文件读取的两种方式
  5. 2018年全国多校算法寒假训练营练习比赛(第三场)
  6. [SpringSecurity]HelloWorld入门案例
  7. 大数据之-Hadoop3.x_Yarn_工作机制---大数据之hadoop3.x工作笔记0142
  8. 精读《如何编译前端项目与组件》
  9. Windows下安装Nginx+php+mysql环境
  10. python用pip安装numpy清华_安装numpy和matplotlib
  11. windows下删除不掉文件夹:找不到该项目无法删除文件夹?
  12. 谈谈我对面向对象的理解
  13. 冰冻三尺,非一日之寒
  14. python算法之lowb排序三人组(冒泡排序,插入排序,选择排序)
  15. 国内投资者投资港股的四种方法和港股必知25件事
  16. 如何写出好文案,不妨看看这篇(上)
  17. 【Redis】Redis介绍
  18. mysql学习日常操作
  19. 项目分享|小师弟手把手教你用蓝牙模块
  20. python传智播客王铭东_传智播客Python学科的王铭东老师讲的怎么样 |

热门文章

  1. Kafka数据迁移MaxCompute最佳实践
  2. Python集合框架
  3. 在自动驾驶技术上,一向自信满满的马斯克也承认了特斯拉的不足
  4. MySQL 5.7: Page Cleaner的刷脏问题
  5. 【转】从CSDN的趣味题学C# 3.0
  6. 在图片上加入删除按钮
  7. AWS API Gateway Swagger定义
  8. nginx + tomcat配置负载均衡
  9. JavaSE生成随机数
  10. jmeter系列六(processor)