Python Matplotlib绘图框
以这幅图为例:Python Matplotlib绘图框,python,matplotlib,Python,Matplotlib,以这幅图为例: import matplotlib.pyplot as plt a = np.arange(0,3, .02) b = np.arange(0,3, .02) c = np.exp(a) # Create plots with pre-defined labels. # Alternatively, you can pass labels explicitly when calling `legend`. fig, ax
import matplotlib.pyplot as plt
a = np.arange(0,3, .02)
b = np.arange(0,3, .02)
c = np.exp(a)
# Create plots with pre-defined labels.
# Alternatively, you can pass labels explicitly when calling `legend`.
fig, ax = plt.subplots()
ax.plot(a, b, 'k', label='Model length')
ax.plot(a, c, 'k:', label='Data length')
# Now add the legend with some customizations.
legend = ax.legend(loc='upper center', shadow=True)
# The frame is matplotlib.patches.Rectangle instance surrounding the
# legend.
frame = legend.get_frame()
frame.set_facecolor('0.90')
plt.show()
这个情节以及我尝试过的许多其他情节都应该有一个框架(4根刺)。
对我来说,它只显示轴,没有刺。我怎样才能改变这一点
编辑:
这里的问题是seaborn图书馆。如果在任何时候导入此库,它将更改matplotlib绘图的格式,并且它们将与上面显示的绘图相似。(更好的设计,但没有刺;)您只需在代码中添加numpy作为np即可
import numpy as np
请参阅中的第三个代码
我得到的是:
您的代码应该显示为带刺的 但是,请尝试向代码中添加以下行
for spine in ax.spines.values():
spine.set_visible(True)
我远非专家,但我通过改变脊椎的颜色解决了同样的问题
for spine in ax.spines.values():
spine.set_color('black')
我已经做了,只是没有展示。我制作的任何图形都没有框架,这太奇怪了。但是谢谢你的建议。即使你尝试了这个代码也没有显示出来吗?导入matplotlib.pyplot作为plt plt.plt([1,2,3,4])plt.ylabel(“一些数字”)plt.show()发现了错误,在某个时候我导入了seaborn,它改变了matplotlib绘图的格式,这就是为什么我的设计看起来也有点不同。我很高兴听到你找到了原因。祝你好运。@Julia如果你已经搞定了,请编辑你的问题(通过添加你是如何解决的)以进行调试,尝试一些可用的默认样式表,这些样式表将覆盖许多可能被破坏的设置。如果这些工作正常,您必须检查,为什么默认情况下内部没有绘制这些脊椎。(在ipython/jupyter?中工作;matplotlib的配置文件(可能称为matplotlib.rc)中的一些未知内容)如果你用一个非默认代码提问,你是在浪费每个人的时间(包括你自己的时间)。