我是matplotlib的新用户,我的平台是Ubuntu 10.04 Python 2.6.5
这是我的代码
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.plot([1,2,3])
Run Code Online (Sandbox Code Playgroud)
错误是:
/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py:41: UserWarning:
Your currently selected backend, 'agg' does not support show().
Please select a GUI backend in your matplotlibrc file ('/usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc')
or with matplotlib.use()
(backend, matplotlib.matplotlib_fname()))
Run Code Online (Sandbox Code Playgroud)
apt-get install libagg但它不起作用.python-gtk2-dev包,但仍然出现错误.这是错误:
>>> matplotlib.use('GTK')
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 95, in <module>
new_figure_manager, draw_if_interactive, show = …Run Code Online (Sandbox Code Playgroud) I am trying to plot a simple graph using pyplot, e.g.:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[5,7,4])
plt.show()
Run Code Online (Sandbox Code Playgroud)
but the figure does not appear and I get the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
Run Code Online (Sandbox Code Playgroud)
I saw in several places that one had to change the configuration of matplotlib using the following:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
I did this, but then got an error message because it …
我正在尝试为 Anscombe 数据集创建 2x2 图
加载数据集并分离数据集中的每个类
import seaborn as sns
import matplotlib.pyplot as plt
anscombe = sns.load_dataset('anscombe')
dataset_1 = anscombe[anscombe['dataset'] == 'I']
dataset_2 = anscombe[anscombe['dataset'] == 'II']
dataset_3 = anscombe[anscombe['dataset'] == 'III']
dataset_4 = anscombe[anscombe['dataset'] == 'IV']
Run Code Online (Sandbox Code Playgroud)
创建一个图形并分为 4 部分
fig = plt.figure()
axes_1 = fig.add_subplot(2,2,1)
axes_2 = fig.add_subplot(2,2,2)
axes_3 = fig.add_subplot(2,2,3)
axes_4 = fig.add_subplot(2,2,4)
axes_1.plot(dataset_1['x'], dataset_1['y'], 'o')
axes_2.plot(dataset_2['x'], dataset_2['y'], 'o')
axes_3.plot(dataset_3['x'], dataset_3['y'], 'o')
axes_4.plot(dataset_4['x'], dataset_4['y'], 'o')
axes_1.set_title('dataset_1')
axes_2.set_title('dataset_2')
axes_3.set_title('dataset_3')
axes_4.set_title('dataset_4')
fig.suptitle('Anscombe Data')
fig.tight_layout()
Run Code Online (Sandbox Code Playgroud)
我在每个地块得到的唯一输出是
[<matplotlib.lines.Line2D at 0x24592c94bc8>]
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试使用来自此站点的 College Scorecard 数据在 MatPlotLib 中创建一个 100% 堆积条形图。
有 38 列是: [在此处插入研究领域] 授予学位的百分比 这解释了为什么有 38 个领域!
我有一个学校的子集,我想为其做这个堆积图。
我尝试按照此处的说明进行操作。是的。这是很长的代码,但我想按本书播放。(加上我在这个博客上一直很幸运)这些数据随这些 PCIP(按研究领域授予的学位百分比)提供,以百分比形式出现,因此我不必遵循 Chris 的计算,因为它们已经完成.
运行代码时出现错误:
bar_width = 1
bar_l = [i for i in range(len(df['PCIP01']))]
tick_pos = [i+(bar_width/2) for i in bar_l]
# Create a figure with a single subplot
f, ax = plt.subplots(1, figsize=(10,5))
ax.bar(bar_l,
degrees.PCIP01,
label='PCIP01',
alpha=0.9,
color='#2D014B',
width=bar_width
)
ax.bar(bar_l,
PCIP04,
label='PCIP04',
alpha=0.9,
color='#28024E',
width=bar_width
)
Run Code Online (Sandbox Code Playgroud)
[对所有剩余的 36 个字段依此类推
# Set the ticks to be School …Run Code Online (Sandbox Code Playgroud) 我想打印一个在Spyder上运行时自动更新的图形。我一直尝试使用matplotlib动画,但是每次要求输入后,它都不会显示图表,而是显示:
matplotlib当前正在使用非GUI后端,因此无法显示该图
我在这里的代码中做错了吗?
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import math
amp=int(input("Please Enter the amplitude-"))
omeg=int(input("Please enter the angular frequency-"))
phdiff=int(input("Please enter the phase difference-"))
t=0
fig=plt.figure()
ax1=fig.add_subplot(111)
def animate(i):
global t
y=amp*math.sin((omeg*t)+phdiff)
fig.clear()
ax1.plot(t,y)
t+=1
animated=anim.FuncAnimation(fig,animate,interval=1000)
fig.show()
Run Code Online (Sandbox Code Playgroud) 这不在jupyter笔记本中,所以这不是这个问题的重复,但我的代码是:
from gluoncv import model_zoo, data, utils
from matplotlib import pyplot as plt
...
plt.show()
Run Code Online (Sandbox Code Playgroud)
我收到的错误是:
/figure.py:445: UserWarning: Matplotlib is currently using ps, which is a non-GUI backend, so cannot show the figure.
% get_backend())
Run Code Online (Sandbox Code Playgroud)
我在https://repl.it/@shamoons/WelloffHarmfulMineral创建了一个 repl
如果重要的话,我使用的是 OS X。我需要做什么才能显示图像?