wordpress网站加速,东莞免费网站制作,机械设备网,三角网站建设原文#xff1a;towardsdatascience.com/how-to-make-cyberpunk-dark-mode-data-visualizations-in-python-b28f82386e75 我一直喜欢图表上有深色背景和霓虹线条#xff0c;因为它们的美学#xff0c;以及它们对某些视力障碍的改善的可访问性——在这篇文章中#xff0c;我…原文towardsdatascience.com/how-to-make-cyberpunk-dark-mode-data-visualizations-in-python-b28f82386e75我一直喜欢图表上有深色背景和霓虹线条因为它们的美学以及它们对某些视力障碍的改善的可访问性——在这篇文章中我们将讨论如何在 Python 中创建一些非常酷且美观的赛博朋克风格图表。ps. 向我的早期分析经理致敬他说我的图表很丑不专业——你可能会讨厌这篇文章https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/86fbda8539f82fed0f535cebe26f22ea.png由我使用 DALL-E 创建的图像。在 Chime我的朋友 Maia Bittner 和我曾使用 Google Sheets 和 Excel 创建类似这样的图表通过手动选择所有霓虹色来使我们的数据引人注目且吸引人。使用这种方法您也可以轻松地在 Python 中生成它们现在让我们看看如何使用 Palmer Penguins 数据集创建一些酷炫的赛博朋克风格霓虹数据可视化您可以通过在 Python 笔记本中安装palmerpenguins直接访问该数据集。 mplcyberpunk一个在 matplotlib 之上创建“赛博朋克”风格图表的*“Python 包只需额外 3 行代码。”*首先在继续之前请确保安装我们将在本教程中需要的包并按如下方式加载 penguins 数据集pip install palmerpenguins pip install mplcyberpunkfrompalmerpenguinsimportload_penguinsimportmatplotlib.pyplotaspltimportmplcyberpunk# Load the penguin datasetpenguinsload_penguins()现在我们已经准备好将赛博朋克融入我们的图表中这个包最适合与折线图一起使用所以让我们看看不同企鹅物种的身体质量分布情况。https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/6635049d5aeb39af40d8e63a17a31766.png由作者创建的图像。以下代码用于生成此数据可视化# Create the plot with the cyberpunk styleplt.style.use(cyberpunk)fig,axplt.subplots(figsize(10,6))# Define the colors for each speciesspecies_colors{Adelie:cyan,Chinstrap:magenta,Gentoo:yellow}# Plot KDE for body mass by speciesforspeciesinpenguins[species].unique():subsetpenguins[penguins[species]species]sns.kdeplot(subset[body_mass_g],axax,lw3,colorspecies_colors[species])# Enhance with cyberpunk stylemplcyberpunk.add_glow_effects()# Manually create legend handles and labelshandles[plt.Line2D([],[],colorspecies_colors[species],labelspecies,linewidth3)forspeciesinpenguins[species].unique()]# Create the legendax.legend(handleshandles,titleSpecies)legendax.get_legend()plt.setp(legend.get_texts(),colorwhite)# Set the title and labelsax.set_title(Body Mass Distribution by Species)ax.set_xlabel(Body Mass (g))ax.set_ylabel(Density)plt.show()另一个如何在想要可视化时间序列数据的情况下创建独特且引人注目的赛博朋克风格图表的例子使用虚拟数据创建的图表——这个包中可用的发光效果特别适合时间序列和百分比变化图表https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/3cacb9aa936a1ef6cd789921c24a0e15.png由作者创建的图像。Cyberpunk 包最适合与折线图一起使用但这里有一个例子说明我们可以如何使用它来在散点图中可视化企鹅统计数据的相关性这仍然看起来相当酷https://github.com/OpenDocCN/towardsdatascience-blog-zh-2024/raw/master/docs/img/a1e066f4f20a737ed979a978bb64acb4.png由作者创建的图像。以下代码用于生成此数据可视化# Create the plot with the cyberpunk styleplt.style.use(cyberpunk)fig,axplt.subplots(figsize(8,6))scatterax.scatter(penguins[flipper_length_mm],penguins[body_mass_g],s30,cpenguins[island].astype(category).cat.codes,cmapcool)# Enhance the plot with cyberpunk style glow effectmplcyberpunk.make_scatter_glow(ax)# Set the title and labelsax.set_title(Penguin Stats- Flipper Length vs Body Mass By Island)ax.set_xlabel(Flipper Length (mm))ax.set_ylabel(Body Mass (g))plt.show()总结来说这个包是您 Python 数据可视化工具箱的一个很好的补充可以提升那些无聊加基本的 matplotlib 图表。作为数据科学家和分析员我们工作的一部分是吸引我们的观众而创建引人注目的图表是其中一种方式。如果您尝试了这个我很乐意听听您的反馈如果您愿意尝试请告诉我✨向这个包的创建者 Dominik Haitz 致以崇高的敬意。您可以在 GitHub 上找到他的作品GitHub – dhaitz/mplcyberpunk: Cyberpunk 风格的 matplotlib 图表如果您喜欢数据AI请查看我的其他故事感谢阅读。SQL 精通数据专业人士的高级技巧