Python Colab的TypeError

发布于 2025-02-12 14:18:56 字数 188 浏览 1 评论 0原文

我使用合作网站在Python中进行了程序,我收到了这个错误,但我不知道如何纠正它。我试图将代码应用于某些数据集,但是我遇到了此错误。这是代码的图片,另一张图片 在此处输入图像描述

I used the Collab website to program in Python and I got this error and I don't know how to correct it. I was trying to apply a code to some dataset, but I encountered this error. Here is a picture of the code and another picture of the error
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花海 2025-02-19 14:18:56

最好看到您的代码尝试精确复制您的情况。

但是,如果我们谈论 labelcolor faceColor 这是一个小例子:

from matplotlib import pyplot as plt
import pandas as pd

# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
# plt.rcParams["figure.autolayout"] = True

# Create a figure and set of subplots
fig, ax = plt.subplots()
ax.set_ylabel('$number$ of clients')

# Get the data
df = pd.read_csv('https://raw.githubusercontent.com/tokern/piicatcher/master/tests/samples/sample-data.csv')
df.groupby(['state'])['city'].count().plot(kind='bar')

# Set the facecolor
ax.set_facecolor('black')

# Set the labelcolor
ax.xaxis.label.set_color('red')
ax.spines['bottom'].set_color('red')
ax.tick_params(axis='x', colors='red')

# Set the legend with other facecolor
ax.legend(fontsize = 11,          
          facecolor = 'lightgray',   
          edgecolor = 'red',   
          title = 'Clients by',    
          title_fontsize = '12',          
         )

plt.title("US Clients")
plt.show()

It will be better to see your code to try to exact reproduce your situation.

But if we talking about labelcolor and facecolor this is the small example:

from matplotlib import pyplot as plt
import pandas as pd

# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
# plt.rcParams["figure.autolayout"] = True

# Create a figure and set of subplots
fig, ax = plt.subplots()
ax.set_ylabel('$number$ of clients')

# Get the data
df = pd.read_csv('https://raw.githubusercontent.com/tokern/piicatcher/master/tests/samples/sample-data.csv')
df.groupby(['state'])['city'].count().plot(kind='bar')

# Set the facecolor
ax.set_facecolor('black')

# Set the labelcolor
ax.xaxis.label.set_color('red')
ax.spines['bottom'].set_color('red')
ax.tick_params(axis='x', colors='red')

# Set the legend with other facecolor
ax.legend(fontsize = 11,          
          facecolor = 'lightgray',   
          edgecolor = 'red',   
          title = 'Clients by',    
          title_fontsize = '12',          
         )

plt.title("US Clients")
plt.show()
谁的新欢旧爱 2025-02-19 14:18:56

您需要删除labelColor参数初始化变量:

fig = plt.figure(
    FigureClass = Waffle, 
    rows = 4,
    columns = 8,
    values = gender,
    colors = ('#B13167', '#3274A1'),
    labels = ['{} - {}'.format(a, b) for a, b in zip(gender.index, gender)],
    legend = {
        'loc': 'upper left', 
        'bbox_to_anchor': (1, 1), 
        'fontsize': 15,
        'title': 'Gender',
        'title_fontsize': 15,
        'facecolor': 'white'
        },
    font_size = 75, 
    icons = ['venus', 'mars'],
    icon_legend = True,
    figsize = (15, 8),
    facecolor = 'black'
)

You need to delete labelcolor parameter when initializing fig variable:

fig = plt.figure(
    FigureClass = Waffle, 
    rows = 4,
    columns = 8,
    values = gender,
    colors = ('#B13167', '#3274A1'),
    labels = ['{} - {}'.format(a, b) for a, b in zip(gender.index, gender)],
    legend = {
        'loc': 'upper left', 
        'bbox_to_anchor': (1, 1), 
        'fontsize': 15,
        'title': 'Gender',
        'title_fontsize': 15,
        'facecolor': 'white'
        },
    font_size = 75, 
    icons = ['venus', 'mars'],
    icon_legend = True,
    figsize = (15, 8),
    facecolor = 'black'
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文