python - 去掉图中的次要框
问题描述
需要从 pyplot 中删除辅助框架(相信是从将图例添加到绘图中)。
首先,我已经阅读了其他关于类似问题的问答。Frameon=False 或 frameon=0 不起作用,我最近重新下载了 matplotlib。其他答案并没有完全解决我的具体问题。我还尝试摆脱 plt.legend(),它摆脱了框架和图例。所以然后我尝试了 plt.legend(frameon=False) 并没有改变。
#Arbitrary runnable code
from getpass import getpass
import numpy as np
import pylab as plt
import matplotlib as mpl
import healpy as hp
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages('KimmiesHistogram.pdf') as pdf:
mpl.rcParams['font.family']='serif'
mpl.rcParams['font.size']=12
fig = plt.figure(figsize= (12,12), frameon= False)
plt.xlabel('MJD: Range')
plt.title("MJD Ranges by Filter")
y= [1, 2,3,45,6,4,34,76,4,34,65,23,34,3,3,9,5,5]
y2=[1, 2,3,45,6,4,34,76,4,34,65,23,34,3,3,9,5,5]
ax1 = fig.add_subplot(132)
ax1.set_xscale('log')
ax1.set_yscale('linear')
plt.hist([y,y2], bins=10, histtype='step', cumulative=1)
plt.show()
谢谢!
解决方案
它不清楚你的真正意思,但我相信你看到了 3 个子图的边界。如果不是这种情况,请澄清您的问题。当我运行你的代码时,我得到了这个:
如果要删除该外框,则只需指定您只想添加 1 个子图,而不是使用 3 个子图的中间ax=fig.add_subplot(111)
。那就是你的问题所在。但老实说,您不需要在示例中添加图形轴来绘制您想要的数据。
#Arbitrary runnable code
from getpass import getpass
import numpy as np
import pylab as plt
import matplotlib as mpl
from matplotlib.backends.backend_pdf import PdfPages
with PdfPages('KimmiesHistogram.pdf') as pdf:
mpl.rcParams['font.family']='serif'
mpl.rcParams['font.size']=12
fig = plt.figure(figsize= (12,12), frameon= False)
plt.xlabel('MJD: Range')
plt.title("MJD Ranges by Filter")
y= [1, 2,3,45,6,4,34,76,4,34,65,23,34,3,3,9,5,5]
y2=[1, 2,3,45,6,4,34,76,4,34,65,23,34,3,3,9,5,5]
ax1 = fig.add_subplot(111)
ax1.set_xscale('log')
ax1.set_yscale('linear')
plt.hist([y,y2], bins=10, histtype='step', cumulative=1)
plt.show()
推荐阅读
- java - 反应原生 webview 与 swift/java webview
- python - Discord.py 在部署到 Heroku 时说“通过了不正确的令牌”
- javascript - 为什么我的嵌套网格视图只显示一瞬间?
- .net - PowerShell 解析 .NET 选项卡完成方法和属性
- python - 使用反斜杠解析非常大的 JSON 文件(JSON 编码)
- ruby-on-rails - 循环中有没有办法知道你是否在最后一次迭代中?
- c++ - 有人可以解释一下吗?这是关于数组和数组内部 if 语句的一些处理
- hex - 这个十六进制校验和是如何计算的?
- python - RabbitMQ Python Pika - 多条消息的连接处理
- python - 卡住了 O(n*logn)