我有这样的情节
fig = plt.figure()
desire_salary = (df[(df['inc'] <= int(salary_people))])
print desire_salary
# Create the pivot_table
result = desire_salary.pivot_table('city', 'cult', aggfunc='count')
# plot it in a separate step. this returns the matplotlib axes
ax = result.plot(kind='bar', alpha=0.75, rot=0, label="Presence / Absence of cultural centre")
ax.set_xlabel("Cultural centre")
ax.set_ylabel("Frequency")
ax.set_title('The relationship between the wage level and the presence of the cultural center')
plt.show()
我想将此添加到subplot
。我尝试
fig, ax = plt.subplots(2, 3)
...
ax = result.add_subplot()
但它返回
AttributeError:“系列”对象没有属性“ add_subplot”。如何检查此错误?
参考方案
matplotlib.pyplot
具有当前图形和当前轴的概念。所有绘图命令均适用于当前轴。
import matplotlib.pyplot as plt
fig, axarr = plt.subplots(2, 3) # 6 axes, returned as a 2-d array
#1 The first subplot
plt.sca(axarr[0, 0]) # set the current axes instance to the top left
# plot your data
result.plot(kind='bar', alpha=0.75, rot=0, label="Presence / Absence of cultural centre")
#2 The second subplot
plt.sca(axarr[0, 1]) # set the current axes instance
# plot your data
#3 The third subplot
plt.sca(axarr[0, 2]) # set the current axes instance
# plot your data
演示:
源代码,
import matplotlib.pyplot as plt
fig, axarr = plt.subplots(2, 3, sharex=True, sharey=True) # 6 axes, returned as a 2-d array
for i in range(2):
for j in range(3):
plt.sca(axarr[i, j]) # set the current axes instance
axarr[i, j].plot(i, j, 'ro', markersize=10) # plot
axarr[i, j].set_xlabel(str(tuple([i, j]))) # set x label
axarr[i, j].get_xaxis().set_ticks([]) # hidden x axis text
axarr[i, j].get_yaxis().set_ticks([]) # hidden y axis text
plt.show()
Matplotlib'粗体'字体 - python跟随this example:import numpy as np import matplotlib.pyplot as plt fig = plt.figure() for i, label in enumerate(('A', 'B', 'C', 'D')): ax = f…
在返回'Response'(Python)中传递多个参数 - python我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…
Python exchangelib在子文件夹中读取邮件 - python我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…
R'relaimpo'软件包的Python端口 - python我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。
Python ThreadPoolExecutor抑制异常 - pythonfrom concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…