LoginSignup
1

More than 1 year has passed since last update.

Organization

Google Colabでplotlyの ```TypeError: imshow() got an unexpected keyword argument 'labels'``` エラー

Google ColabでTypeError: imshow() got an unexpected keyword argument 'labels'エラー

TL;DR

# plotlyをアップグレードして, Google Colabのランタイムを再起動(出荷状態に戻すとバージョンがまた元に戻るので注意)
!pip install --upgrade plotly

問題

  • Google Colabで, plotlyでヒートマップなどを表示しようとして, 軸ラベルを付与しようとしたら TypeError: imshow() got an unexpected keyword argument 'labels' と怒られてしまった.
data=[[1, 25, 30, 50, 1], [20, 1, 60, 80, 30], [30, 60, 1, 5, 20]]
fig = px.imshow(data,
                labels=dict(x="Day of Week", y="Time of Day", color="Productivity"),
                x=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
                y=['Morning', 'Afternoon', 'Evening']
               )
fig.update_xaxes(side="top")
fig.show()

image.png

原因

対策

  • plotlyのバージョンをアップグレードして, Google Colabのランタイムを再起動する.
  • その後, 4.14.0になりlabelsが利用できるようになる.
import plotly
print(plotly.__version__)

image.png

image.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1