[파이썬] seaborn 커스텀 마커 및 라인 스타일

Seaborn is a popular data visualization library in Python that provides a high-level interface for creating attractive and informative statistical graphics. It offers various styles and options to customize the appearance of plots, including markers and line styles.

In this blog post, we will explore how to customize markers and line styles in seaborn plots.

Customizing Markers

Seaborn allows you to customize the markers used in scatter plots. You can choose from a wide range of built-in markers or create your own custom markers.

To use a custom marker, you need to specify the marker parameter in the scatter plot function. Here’s an example:

import seaborn as sns
import matplotlib.pyplot as plt

# Create dummy data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

# Create a scatter plot with a custom marker
sns.scatterplot(x=x, y=y, marker='^')

# Show the plot
plt.show()

In the above code, we import seaborn as sns and matplotlib.pyplot as plt. We create some dummy data for x and y coordinates, and then call the sns.scatterplot() function to create a scatter plot with a custom marker. In this case, we use the ‘^’ symbol as the marker.

You can experiment with different marker options such as ‘o’ for circles, ‘s’ for squares, ‘d’ for diamonds, and more. Seaborn also supports additional marker customization options such as marker size, marker color, and alpha value.

Customizing Line Styles

Seaborn also allows you to customize the line styles in line plots. By default, seaborn uses a solid line style for line plots, but you can choose from various line styles such as dashed, dotted, or a combination of both.

To specify a custom line style, you need to use the linestyle parameter in the line plot function. Here’s an example:

import seaborn as sns
import matplotlib.pyplot as plt

# Create dummy data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

# Create a line plot with a custom line style
sns.lineplot(x=x, y=y, linestyle='--')

# Show the plot
plt.show()

In the above code, we import seaborn as sns and matplotlib.pyplot as plt. We create some dummy data for x and y coordinates and then call the sns.lineplot() function to create a line plot with a dashed line style. We use ‘–’ as the line style for this example.

In addition to dashed lines (‘–’), you can also use other line styles such as dotted lines (‘.’), dash-dot lines (‘-.’), and more.

Conclusion

In this blog post, we explored how to customize markers and line styles in seaborn plots. By using custom markers and line styles, you can create visually appealing and unique visualizations that suit your data and storytelling requirements.

Seaborn provides a wide range of options to customize the appearance of plots, and you can further enhance your plots by combining marker and line style customizations with other seaborn features such as color palettes and plot labels.