[파이썬] bokeh 기본 그래프 생성

Bokeh is a powerful data visualization library in Python that allows you to create interactive plots and charts. In this blog post, we will explore how to create basic graphs using Bokeh.

Installation

Before we get started, make sure you have Bokeh installed in your Python environment. You can install it using pip:

pip install bokeh

Once installed, you are ready to create your first Bokeh graph!

Basic Graph with Bokeh

To create a basic graph with Bokeh, we need to import the necessary modules and data, create a figure object, and then plot the data on the figure.

Let’s start by importing the required modules and generating some sample data:

import numpy as np
from bokeh.plotting import figure, show

# Generate some sample data
x = np.linspace(0, 10, 100)
y = np.sin(x)

Next, we need to create a figure object. The figure() function is used to define the properties of the graph such as the size, title, axes labels, etc.

# Create a figure object
p = figure(title="Basic Bokeh Graph", x_axis_label='X', y_axis_label='Y')

Now, we can plot our data on the figure. The line() method is used to draw a line plot. We pass in the x and y coordinates as arguments.

# Plot the data
p.line(x, y, line_width=2)

Finally, we can display the graph using the show() function.

# Display the graph
show(p)

And there you have it! A basic graph created using Bokeh. You can customize various aspects of the graph such as the line color, line width, and plot markers. Bokeh provides a wide range of options to make your graphs more visually appealing and interactive.

Conclusion

Bokeh is a great library for creating interactive data visualizations in Python. In this blog post, we learned how to create a basic graph using Bokeh. With Bokeh, you can create stunning visualizations for your data and explore it in a more interactive way.

Stay tuned for more blog posts on advanced Bokeh topics and tips! Happy coding!