
まくまく
プラグラミング言語「PYTHON」を使ってみよう!!業務自動化・効率化の実例を踏まえ、解説できればと思っています。対象は、プログラムを学び始めた初心者向けとなります。
今回の内容
前回の記事で作成した等高線図のグラフの色を変更します。
前回の記事はこちらです。エクセルに入力された100点の値から等高線図を作成しています。
使用するのはPlotly
使用するライブラリは、見た目のよいイマドキのグラフが作成できるPlotly。エクセルでは作れない高度なグラフも作成できるおすすめのライブラリです。
ここではPlotlyがインストールされているのを前提として書き進めていきます。
サンプルコード
import pandas as pd
import plotly
import plotly.graph_objects as go
df = pd.read_excel('contourdata.xlsx')
df_s = df.sort_index(ascending=False)
fig = go.Figure(data =go.Contour(z=df_s))
fig.update_layout(title='Sample Graph', autosize=False,
width=500, height=500,
margin=dict(l=30, r=30, b=30, t=60))
fig.update_layout(xaxis=dict(tickvals=[]),yaxis=dict(tickvals=[]))
fig.update_traces(zmin=1.0,zmax=1.6,colorscale= 'YlOrrd')
fig.show()
コメント
- 13行目「fig.update_traces〜」の行に「colorscale= ‘YlOrrd’」を追加
- 上記の「YlOrrd」がカラースケール
色を変更するときは、上の「YlOrrd」の部分を変更します。変更できる色は下記の種類です。下記のいずれかに変更すると色が変わります。
aggrnyl agsunset blackbody bluered blues blugrn bluyl brwnyl
bugn bupu burg burgyl cividis darkmint electric emrld
gnbu greens greys hot inferno jet magenta magma
mint orrd oranges oryel peach pinkyl plasma plotly3
pubu pubugn purd purp purples purpor rainbow rdbu
rdpu redor reds sunset sunsetdark teal tealgrn turbo
viridis ylgn ylgnbu ylorbr ylorrd algae amp deep
dense gray haline ice matter solar speed tempo
thermal turbid armyrose brbg earth fall geyser prgn
piyg picnic portland puor rdgy rdylbu rdylgn spectral
tealrose temps tropic balance curl delta oxy edge
hsv icefire phase twilight mrybm mygbm
bugn bupu burg burgyl cividis darkmint electric emrld
gnbu greens greys hot inferno jet magenta magma
mint orrd oranges oryel peach pinkyl plasma plotly3
pubu pubugn purd purp purples purpor rainbow rdbu
rdpu redor reds sunset sunsetdark teal tealgrn turbo
viridis ylgn ylgnbu ylorbr ylorrd algae amp deep
dense gray haline ice matter solar speed tempo
thermal turbid armyrose brbg earth fall geyser prgn
piyg picnic portland puor rdgy rdylbu rdylgn spectral
tealrose temps tropic balance curl delta oxy edge
hsv icefire phase twilight mrybm mygbm
出力(色のサンプル)
↑Plotlyを使うならこれ!!Plotly&Dashが学べます!