การปรับแต่งแกน

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

George Boorman

Core Curriculum Manager, DataCamp

กราฟเส้น

source = ColumnDataSource(data=apple)
fig = figure(x_axis_label="Date", y_axis_label="Market Cap ($)")
fig.line(x="date", y="market_cap", source=source)

output_file(filename="unformatted_plot.html") show(fig)

apple_unformatted

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

ประเภทแกน X

source = ColumnDataSource(data=apple)
fig = figure(x_axis_label="Date", y_axis_label="Market Cap ($)",

x_axis_type="datetime")
fig.line(x="date", y="market_cap", source=source) output_file(filename="unformatted_plot.html") show(fig)

x_axis_type_plot

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

ตัวเลือกการจัดรูปแบบ

  • NumeralTickFormatter
  • อาร์กิวเมนต์: format
ค่า format ผลลัพธ์
1500.00 "$0.00" $1500.00
2000.00 "$0" $2000
5000.00 "$0,0" $5,000
1100000 "$0.0a" $1.1m
5000000000 "$0a $5b
  • DatetimeTickFormatter
  • อาร์กิวเมนต์: months
ค่า months ผลลัพธ์
"2018-03-01" "%B %Y" "March 2018"
"2019-10-15" "%b %Y" "Oct 2019"
"2020-02-09" "%b %y" "Feb 20"
  • อาร์กิวเมนต์อื่น ๆ:
    • microseconds, milliseconds, seconds, minisec, minutes, hourmin, hours, days, years
การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

NumeralTickFormatter

from bokeh.models import NumeralTickFormatter

fig = figure(x_axis_label="Date", y_axis_label="Price ($)") fig.line(x="date", y="market_cap", source=source)
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0.0a")
output_file(filename="formatted_y_axis.html") show(fig)

apple_formatted_y_axis

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

DatetimeTickFormatter

from bokeh.models import NumeralTickFormatter, DatetimeTickFormatter

fig = figure(x_axis_label="Date", y_axis_label="Price ($)") fig.line(x="date", y="price", source=source) fig.yaxis[0].formatter = NumeralTickFormatter(format="$0.0a")
fig.xaxis[0].formatter = DatetimeTickFormatter(months="%b %Y")
output_file(filename="formatted_market_cap.html") show(fig)
การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

กราฟขั้นสุดท้าย

apple_formatted

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

มาฝึกกันเถอะ!

การสร้างภาพข้อมูลแบบอินเทอร์แอกทีฟด้วย Bokeh

Preparing Video For Download...