The most powerful Python visualization artifact, have you used it?

Data analysis is inseparable from data visualization. The most commonly used ones are Pandas, Matplotlib, Pyecharts, and of course Tableau. After reading an article introducing Plotly charting, I was eager to try it. I checked the relevant information and started trying to use it for charting.

1、Plotly

Plotly is an online platform for data analysis and visualization. It is very powerful and can draw many graphics online, such as bar charts, scatter plots, pie charts, histograms, etc.

And it still supports online editing, and many APIs such as Python, Javascript, Matlab, R, etc. in multiple languages.

It is also very simple to use in Python, just use Pip Install Plotly directly.

It is recommended to use it in Jupyter notebook, and Pycharm operation is not very convenient.

Using Plotly, you can draw many high-quality graphs comparable to Tableau:

Plotly mapping

I tried to make a line chart, scatter plot and histogram, first import the library:

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 离线模式
plotly.offline.init_notebook_mode(connected=True)

The above lines of code mainly refer to some libraries. Plotly has two modes: online and offline. The online mode requires an account to edit in the cloud.

The offline mode I chose, Plotly can be displayed directly in the Notebook if it is set to Offline mode.

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)

line chart

Randomly set 4 parameters, one x-axis number and three y-axis random data to make three different types of graphs.

Trace0 is Markers, Trace1 is Lines and Markers, Trace3 is Lines.

Then put the three graphs in the Data list and call py.iplot(data). The default color scheme of the drawn picture system is also pretty good~/

3. Make a scatter plot

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)

Setting the Mode to Markers is a scatter plot, and then setting a set of parameters in the Marker, such as the random range of the color, the size of the scatter point, and the legend, etc.

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 is a kind of graph we commonly use. The way Plotly draws histogram is somewhat similar to what we set in Pandas. They very intuitively reflect the difference between two productivity in different months.

The drawing above is just the tip of the iceberg of Plotly, which are some of the most basic usages. It also has many cool usages and graphics, especially the pictures drawn in combination with Pandas are very beautiful.

For example, the K-line charts of some stocks, if you are interested, you can study them~

Getting Started with Data Analysis:

  Dark horse programmer MySQL knowledge intensive + mysql practical case

Quickly build a BI business big data analysis platform from scratch in 3 days_li

  Dark horse programmer MySQL knowledge intensive + mysql practical case


 

Big Data Basics - TiDB Database from Entry to Practice_


 

Big data introductory tutorial, very suitable for Xiaobai's big data self-study course_i

Guess you like

Origin blog.csdn.net/JACK_SUJAVA/article/details/129691824