python - 在 python 中(plt.table 在第一行设置 rowColours)
问题描述
嗨,当我想为表格的第一行设置颜色时,我总是会出错。我想创建一个表格并用颜色突出显示第一行。有没有其他方法可以塑造它?编辑这里是我的完整代码
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import table
#first_page
DATA_FILE = "C:/test/corr.xlsx"
df = pd.read_excel("C:/test/corr.xlsx")
s = df.iloc[0:15, 0:10]
fig, ax = plt.subplots(figsize=(5, 1))
plt.suptitle("1.Excel-Daten", fontsize =15)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
ax.set_frame_on(False)
tabla = table(ax, s, colWidths=[0.30]*len(df.columns), rowColours='r',
colColours = 'r')
tabla.auto_set_font_size(False)
tabla.set_fontsize(15)
tabla.scale(1.5,1.5)
plt.show
我的错误是:
runfile('C:/Users/ucarm.lokal/.spyder-py3/untitled17.py', wdir='C:/Users/ucarm.lokal/.spyder-py3') Traceback(最近一次通话最后):
文件“”,第 1 行,在 runfile('C:/Users/ucarm.lokal/.spyder-py3/untitled17.py', wdir='C:/Users/ucarm.lokal/.spyder-py3')
文件“C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 705 行,运行文件 execfile(文件名,命名空间)
文件“C:\Anaconda\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 102 行,在 execfile exec(compile(f.read(), filename, 'exec'), namespace)
文件“C:/Users/ucarm.lokal/.spyder-py3/untitled17.py”,第 25 行,在 tabla = table(ax, s, colWidths=[0.30]*len(df.columns), rowColours='r ', 颜色颜色 = 'r')
文件“C:\Anaconda\lib\site-packages\pandas\plotting_tools.py”,第 65 行,在表 colLabels=colLabels,**kwargs 中)
文件“C:\Anaconda\lib\site-packages\matplotlib\table.py”,第 652 行,表格中 text=colLabels[col],facecolor=colColours[col],
IndexError: string index out of range
解决方案
推荐阅读
- react-native - 将导航从子组件传递到父组件获取 TypeError
- flutter - Flutter:如何从 Firebase 获取实时数据库(导入的 Json)中的数据
- python-3.x - 通过 stackoverflow 错误使用 Selenium 登录 Google
- java - Jitpack 任务“安装”在根项目 Android 库中不明确
- java - wsdl 中缺少元素
- elixir - 如何在 LiveView 中更新嵌套分配的值
- amazon-web-services - AWS ALB 的 JWT 声明验证返回 403 Access Denied
- python - Keras ImageDataGenerator 逻辑是什么?
- matlab - 将向量拆分为子向量 MATLAB
- php - 在 PHP 中将数据存储在全局变量中