Legend 从panda中的子绘图中删除单个图例

Legend 从panda中的子绘图中删除单个图例,legend,subplot,Legend,Subplot,我想删除熊猫中单个子地块的图例。我创建了一个条形图和#子图。我想保留每个子地块的标题并删除图例,因为它们显示的是相同的措辞。我尝试了几种技巧,甚至有些技巧让我呼吁每一个人#子地块,但我确信有一个简单的解决方案。下面的第四个结果图像是我需要帮助的图像 以下是我目前的代码: import matplotlib.pyplot as plt import pandas as pd import scipy.stats as st import numpy as np mouse_metadata =

我想删除熊猫中单个子地块的图例。我创建了一个条形图和#子图。我想保留每个子地块的标题并删除图例,因为它们显示的是相同的措辞。我尝试了几种技巧,甚至有些技巧让我呼吁每一个人#子地块,但我确信有一个简单的解决方案。下面的第四个结果图像是我需要帮助的图像

以下是我目前的代码:

import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
import numpy as np

mouse_metadata = "Mouse_metadata.csv"
study_results = "Study_results.csv"

mouse_metadata = pd.read_csv(mouse_metadata)
study_results = pd.read_csv(study_results)

study_data_combined = pd.merge(mouse_metadata,study_results, on= "Mouse ID")
pyma_sd = study_data_combined
pyma_sd.head()


**

只需在调用
DataFrame.plot.bar
时提供
legend=False

import matplotlib.pyplot as plt
import pandas as pd

speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant', 'rabbit', 'giraffe', 'coyote', 'horse']
df = pd.DataFrame({'speed': speed, 'lifespan': lifespan}, index=index)
axes = df.plot.bar(rot=0, subplots=True, legend=False)
plt.show()


将上面的图像与在调用
DataFrame.plot.bar中生成的图像进行比较。

只需提供
legend=False

import matplotlib.pyplot as plt
import pandas as pd

speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant', 'rabbit', 'giraffe', 'coyote', 'horse']
df = pd.DataFrame({'speed': speed, 'lifespan': lifespan}, index=index)
axes = df.plot.bar(rot=0, subplots=True, legend=False)
plt.show()


将上面的图像与中生成的图像进行比较。

我修复了一些格式并将图像内联。我修复了一些格式并将图像内联。感谢您的快速响应,效果非常好……非常感谢@Cmac不用担心!请随意。谢谢,这非常有效,这里是最终结果:#使用pandas axes=pyma\u sd\u grouped\u stats.plot.bar(rot=50,subplot=True,figsize=(10,6),width=0.75,legend=False)plt.subplot\u adjust(hspace=0.5)plt.suptitle生成显示每个治疗方案的数据点数量的单独图表(“每种药物方案的个人统计数据”)plt.show()感谢您的快速反应,效果非常好…非常感谢!@Cmac无需担心!请随意。谢谢,效果非常好,最后的结果如下:#使用pandas axes=pyma\u sd\u group\u stats.plot.bar(rot=50,subplot=True,figsize=(10,6),宽度=0.75,图例=False)plt.subplot_adjust(hspace=0.5)plt.suptitle(“每个药物方案的个体统计数据”)plt.show()
axes = pyma_sd_grouped_stats.plot.bar(rot=50, subplots=True, figsize = (10, 6), width = .75,)
axes[1].legend(loc=1)
plt.subplots_adjust(hspace=0.5)
plt.show()
import matplotlib.pyplot as plt
import pandas as pd

speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant', 'rabbit', 'giraffe', 'coyote', 'horse']
df = pd.DataFrame({'speed': speed, 'lifespan': lifespan}, index=index)
axes = df.plot.bar(rot=0, subplots=True, legend=False)
plt.show()