程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The strongest Python visual artifact, I suggest you try!

編輯:Python

Data analysis is inseparable from data visualization , The one we use most often is pandas,matplotlib,pyecharts Of course, Tableau, See an article about plotly After drawing, I'm also eager to try , After checking the relevant information, I began to try to draw with it .

1. Plotly

Plotly It is an online platform for data analysis and visualization , Very powerful , You can draw a lot of graphs online, such as bar graphs 、 Scatter plot 、 The pie chart 、 Histogram and so on . It also supports online editing , And many languages python、javascript、matlab、R Wait a lot API. It's in python It's easy to use in , Direct use pip install plotly That's all right. . It's best to recommend jupyter notebook Use in ,pycharm The operation is not very convenient . Use Plotly Can draw a lot like Tableau High quality map of :

plotly Drawing I tried to make a line chart 、 Scatter and histogram , Import library first :

from plotly.graph_objs import Scatter,Layout
import plotly
import plotly.offline as py
import numpy as np
import plotly.graph_objs as go
#setting offilne Offline mode
plotly.offline.init_notebook_mode(connected=True)

The above lines of code mainly refer to some libraries ,plotly There are online and offline modes , Online mode requires an account that can be edited in the cloud . The offline mode I chose ,plotly Set to offline Mode can be directly in notebook It shows .

2. Make a line chart

N = 100
random_x = np.linspace(0,1,N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5
#Create traces
trace0 = go.Scatter(
x = random_x,
y = random_y0,
mode = 'markers',
name = 'markers')
trace1 = go.Scatter(
x = random_x,
y = random_y1,
mode = 'lines+markers',
name = 'lines+markers'
)
trace2 = go.Scatter(
x = random_x,
y = random_y2,
mode = 'lines',
name = 'lines'
)
data = [trace0,trace1,trace2]
py.iplot(data)

Broken line diagram

Random setting 4 Parameters , One x The number of axes and three y Random data of the axis , Make three different types of drawings .trace0 yes markers,trace1 yes lines and markers,trace3 yes lines. Then put the three diagrams on data In this list , call py.iplot(data) that will do . The default color of the drawn picture system is also very good-looking ~

3. Make a scatter chart

trace1 = go.Scatter(
y = np.random.randn(500),
mode = 'markers',
marker = dict(
size = 16,
color = np.random.randn(500),
colorscale = 'Viridis',
showscale = True
)
)
data = [trace1]
py.iplot(data)

hold mode Set to markers It's a scatter plot , then marker Set a set of parameters , For example, the random range of colors , The size of the scatter , And legends and so on .

4. Histogram

trace0 = go.Bar(
x = ['Jan','Feb','Mar','Apr', 'May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'],
y = [20,14,25,16,18,22,19,15,12,16,14,17],
name = 'Primary Product',
marker=dict(
color = 'rgb(49,130,189)'
)
)
trace1 = go.Bar(
x = ['Jan','Feb','Mar','Apr', 'May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec'],
y = [19,14,22,14,16,19,15,14,10,12,12,16],
name = 'Secondary Product',
marker=dict(
color = 'rgb(204,204,204)'
)
)
data = [trace0,trace1]
py.iplot(data)

Histogram

Histogram is a commonly used graph ,plotly The way we draw the histogram is the same as us pandas The settings inside are a little similar , They intuitively reflect the difference between two productivity in different months . The drawing above is just plotly The tip of the iceberg , Are some of the most basic uses , It also has many cool uses and graphics , Especially with pandas The picture combined with the drawing is very beautiful . For example, some stocks K Line graph , If you are interested, you can study ~ Link here :https://plot.ly/python/

Link to the original text :https://www.jianshu.com/p/e5fb1b5c0957


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved