请不要更多的基本情节

“If I see one more basic blue bar plot…”

“如果我再看到一个基本的蓝色条形图……”

After completing the first module in my studies at Flatiron School NYC, I started playing with plot customizations and design using Seaborn and Matplotlib. Much like doodling during class, I started coding other styled plots in our jupyter notebooks.

在纽约Flatiron学校完成学习的第一个模块后,我开始使用Seaborn和Matplotlib进行剧情定制和设计。 就像在上课时涂鸦一样,我开始在我们的Jupyter笔记本中编写其他样式的图。

After reading this article, you’re expected to have at least one quick styled plot code in mind for every notebook.

阅读本文后,您应该为每个笔记本至少记住一个快速样式化的绘图代码。

没有更多的默认情况下,品牌专卖店,基本情节, (No more default, store brand, basic plots, please!)

如果您无能为力,请使用Seaborn。 (If you can do nothing else, use Seaborn.)

You have five seconds to make a decent looking plot or the world will implode; use Seaborn!

您有五秒钟的时间可以绘制出像样的情节,否则世界将会崩溃。 使用Seaborn!

Seaborn, which is build using Matplotlib can be an instant design upgrade. It automatically assigns the labels from your x and y values and a default color scheme that’s less… basic. ( — IMO: it rewards good, clear, well formatted column labeling and through data cleaning) Matplotlib does not do this automatically, but also does not ask for x and y to be defined at all times depending on what you are looking to plot.

使用Matplotlib构建的Seaborn可以立即进行设计升级。 它会根据您的x和y值自动分配标签,并且使用默认的配色方案(基本)。 (— IMO:它会奖励良好,清晰,格式正确的列标签以及通过数据清理)Matplotlib不会自动执行此操作,但是也不会始终根据要绘制的内容要求定义x和y。

Here are the same plots, one using Seaborn and one Matplotlib with no customizations.

这是相同的图,一个使用Seaborn,另一个使用Matplotlib,没有进行自定义。

Image for post
Image for post
Seaborn — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — Matplotlib
Seaborn — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —并将

从顶部样式化 (Style it from the top)

Depending on the data you are visualizing, changing the style and backgrounds may increase interpretability and readability. You can carry this style throughout by implementing a style at the top of your code.

根据所显示的数据,更改样式和背景可能会提高解释性和可读性。 您可以通过在代码顶部实现样式来贯穿整个样式。

There is a whole documentation page on styline via Matplotlib.

通过Matplotlib在样式上有一个完整的文档页面。

# insert a style under your libraries to set the tone for your entire notebook
# Use styles like 'ggplot', 'dark_background', or 'fivethirtyeight'


import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline


plt.style.use('ggplot')


# More on color below, but you can also set a color palette at the top
# Or set the plt style using the seaborn styles in matplotlib


# sns.set_palette('colorblind')
# plt.style.use('seaborn-colorblind')

Styling can be as simple as setting the style with a simple line of code after your imported libraries. GGPlot changed the background to grey, and has a specific font. There are many more styles you can tryout.

样式设置很简单,就像在导入的库之后用简单的代码行设置样式一样。 GGPlot将背景更改为灰色,并具有特定的字体。 您可以尝试更多样式。

Image for post
Using plot styling, Matplotlib (top) Seaborn (bottom) Notice that Seaborn automatically labeled the plot.
使用绘图样式,Matplotlib(顶部)Seaborn(底部)请注意,Seaborn自动标记了绘图。

XKCD; 厚脸皮的小东西 (XKCD; a cheeky little extra)

# If you want to be cheeky, you can use the xkcd styled plot
# However, you'll want to run plt.rcdefaults() after to clear this style if you don't want them to continue. 
# The XKCD style acts differently than normal styling. 
# plt.xkcd()

Fun. Not professional. But so fun.

好玩 不专业。 但是很好玩。

Image for post

Be aware that if you use this XKCD style it will continue until you reset the defaults by running plt.rcdefaults()…

请注意,如果使用此XKCD样式,它将继续进行,直到通过运行plt.rcdefaults()重置默认值为止。

漂亮的颜色哦! (PRETTY COLORS OMG!)

Image for post
- Seaborn single color names. These can also be used in Matplot Lib. Image from Matplotlib.org
-Seaborn单色名称。 这些也可以在Matplot库中使用。 图片来自Matplotlib.org

Make your plots engaging. Color theory comes into play here. Seaborn has a mix of palettes which can also be used in Matplot lib, plus you can also make your own.

让您的情节吸引人。 颜色理论在这里起作用。 Seaborn有多种调色板,也可以在Matplot lib中使用,此外您还可以自己制作。

Single Colors: One and Done

单色:一种完成

  • Above is a list of single color names you can call to change lines, scatter plots, and more.

    上面是一个单色名称的列表,您可以调用它们来更改线条,散布图等。

Lazy? Seaborn’s Default Themes

懒? Seaborn的默认主题

  • has six variations of default

    有六种默认值
  • deep, muted, pastel, bright, dark, and colorblind

    deepmutedpastelbrightdarkcolorblind

  • use color as an argument after passing in x, y, and data

    传入x,y和数据后,将color用作参数
  • color = ‘colorblind’

    color ='色盲'

Work Smarter Not Harder: Pre-Fab Palettes

更加聪明地工作:预制调色板

color_palette() accepts any seaborn palette or matplotlib colormap

color_palette()接受任何seaborn调色板或matplotlib颜色图

  • Personal favorites are ‘magma’ and ‘viridis’

    个人最爱是“岩浆”和“ viridis”

Control Freak? Custom Palettes / Using Hex Codes

控制怪胎? 自定义调色板/使用十六进制代码

  • pretty_colors = [“#FF4653”, “#EE7879”,“#DDEDF4”, “#2A3166”]

    pretty_colors = [“#FF4653”,“#EE7879”,“#DDEDF4”,“#2A3166”]
  • pass in hex codes which can be found online

    传递可以在网上找到的十六进制代码
  • create a kind and add in specifics, play around with the parameters for more customized palettes

    创建种类并添加详细信息,使用参数创建更多自定义调色板
Image for post
Many ways to choose a color palette.
选择调色板的多种方法。

一切都应该有标签 (Everything Should Have a Label)

Here we are using Matplotlib, but we have added a single color for each line, a title, x and y labels, and a legend for clear concise interpretation.

在这里,我们使用Matplotlib,但为每行添加了一种颜色,标题,x和y标签以及图例,以使内容简洁明了。

Every variable has a home, and it sparks joy now, right? — Think how would Marie Kondo code.

每个变量都有一个家,现在它会激发欢乐,对吗? —想想Marie Kondo的代码。

plt.style.use('seaborn')
fig=plt.figure(figsize = (18,10))




python = plt.plot('Python', data = df, color = 'forestgreen')
javascript = plt.plot('JavaScript', data = df, color = 'darkorange')


plt.title('Python vs JavaScript Developer Salaries', size = 30)


plt.xlabel('Age', size = 25)
plt.xticks(size = 15)


plt.ylabel('Salaries', size = 25)
plt.yticks(size = 15)


plt.legend(labels = ['Python Developers', 'JavaScript Developers'], prop={"size":16}, loc = 'center right');

Simple, but clear.

简单但清晰。

Image for post

Overall, pretty simple right? Well, now you have no excuses for those ugly basic plots. I hope you found this helpful and mayb a little bit fun. There’s so much more on color and design in the documentation, so once you’ve mastered these quick tips, dive in on the documentation below!

总体来说,很简单吧? 好吧,现在您没有那些难看的基本情节的借口。 我希望您觉得这很有帮助,可能会有点有趣。 文档中包含有关颜色和设计的更多内容,因此,一旦您掌握了这些快速提示,请深入阅读以下文档!

Enjoy? Let’s be friends. Follow me on GitHub, Instagram, and Medium

请享用? 成为朋友吧。 在GitHubInstagramMedium上关注我

Today’s Data by Corey Schaffer: Developer Salaries Data

今日数据作者:Corey Schaffer :开发人员薪金数据

Documentation:

说明文件:

Seaborn

Seaborn

Matplotlib

Matplotlib

Other Resources:

其他资源:

XKCD in Matplotlib

Matplotlib中的XKCD

翻译自: https://medium.com/python-in-plain-english/no-more-basic-plots-please-59ecc8ac0508

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值