“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,沒有進行自定義。


從頂部樣式化 (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 inlineplt.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將背景更改為灰色,并具有特定的字體。 您可以嘗試更多樣式。

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.
好玩 不專業。 但是很好玩。

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!)

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
, andcolorblind
deep
,muted
,pastel
,bright
,dark
和colorblind
- 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 創建種類并添加詳細信息,使用參數創建更多自定義調色板

一切都應該有標簽 (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.
簡單但清晰。

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
請享用? 成為朋友吧。 在GitHub , Instagram和Medium上關注我
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
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/389171.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/389171.shtml 英文地址,請注明出處:http://en.pswp.cn/news/389171.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!