Get the App
SLTechnology News&Howtos  ›  Development  › 

How to draw a chart with Python matplotlib plotly

Shulou Source: shulou.com Published: 2022-06-01 05:34:56 10月03日 Update

This article mainly explains "how to draw a chart with Python matplotlib plotly", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to draw a chart with Python matplotlib plotly" bar!

I. collate the data

Using 300 movies as data source

Import pandas as pd cnboo=pd.read_excel ("cnboNPPD1.xls") cnboo

Import seaborn as snsimport numpy as np import matplotlib as mplfrom matplotlib import pyplot as plt import pandas as pd from datetime import datetime,timedelta%matplotlib inlineplt.rcParams ['font.sans-serif'] = [' SimHei'] # is used to display the Chinese label plt.rcParams ['axes.unicode_minus'] = False # to display the negative sign from datetime import datetime! Pip install plotly # install import matplotlib.pyplot as pltimport plotlyfrom plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplotx=cnboo ['BO'] .tolist () y=cnboo [' PERSONS'] .tolist () dict01= {"x": X, "y": y} dict01 II, line chart # line chart iplot ([dict01])

3. Scatter plot import plotly.graph_objs as goiplot ([go.Scatter (Xerox recording yearly recording markers'))

# randomly generated dot graph import numpy as npiplot ([go.Scatter (x=np.random.randn), y=np.random.randn (100), mode='markers')] go

Trace=go.Scatter (x=cnboo ['PRICE'],) data= [trace] iplot (data)

Trace=go.Scatter (x=cnboo ['PRICE'], data= [trace] iplot (data)

Pie chart colors= ['# dc2624','#2b4750','#45a0a2','#e87a59','#7dcaa9','#649E7D','#dc8018','# C89F91', '6c6d6c',' 4f6268', 'filmtype=cnboo [' TYPE'] filmbo=cnboo ['PRICE'] trace=go.Pie (labels=filmtype,values=filmbo, hoverinfo='label+percent',textinfo='value',textfont=dict (size=10), marker=dict (color='#000000') Width=3)) data= [trace] iplot (data)

Filmtype=cnboo ['TYPE'] filmbo=cnboo [' PRICE'] trace=go.Pie (labels=filmtype,values=filmbo, hoverinfo='label+percent',textinfo='value',textfont=dict (size=12), marker=dict (colors=colors)) data= [trace] iplot (data)

Bar chart # plotly bartrace1=go.Bar (x=cnboo ['TYPE'], y=cnboo [' PRICE'], name= "types and fares") trace2=go.Bar (x=cnboo ['TYPE'], yearly TYPE' name = "Type and number of people") layout=go.Layout (title= "relationship between Chinese Film types and ticket prices, number of people", xaxis=dict (title=' Film genre')) data= [trace1,trace2] fig=go.Figure (data,layout=layout) iplot (fig)

Dot map (setting multiple go objects) trace1=go.Scatter (x=cnboo ['TYPE'], y=cnboo [' PRICE'], name= "Type and fare", mode= "markers", marker=dict (color= "red", size=8)) trace2=go.Scatter (x=cnboo ['TYPE'], y=cnboo [' PERSONS'], name= "Type and number", mode= "markers", marker=dict (color= "blue", size=5)) data= [trace1,trace2] iplot (data)

Trace1=go.Scatter (x=cnboo ['TYPE'], y=cnboo [' PRICE'], name= "genres and fares", mode= "markers", marker=dict (color= "red", size=8)) trace2=go.Scatter (x=cnboo ['TYPE'], y=cnboo [' PERSONS'], name= "genres and people", mode= "markers", marker=dict (color= "blue", size=5) layout=go.Layout (title= "Chinese Movie genres and fares" Number of people ", plot_bgcolor=" # FFFFFF ") data= [trace1,trace2] fig=go.Figure (data,layout=layout) iplot (fig)

7. 2D density map import plotly.figure_factory as fffig=ff.create_2d_density (fig,filename=' score and person-time') iplot (fig,filename=' score and person-time)

Colorscale= ['rgb (20,38,220)', 'rgb (255,255,255)'] # the last color is the calling background fig=ff.create_2d_density (fig,filename=' score and person-times')

8. Simple 3D map layout=go.Layout (title= "relationship between Chinese box office and ticket prices", barmode= "group") trace01=go.Scatter3d (x=cnboo ['BO'], y=cnboo [' PRICE'], z=cnboo ['PERSONS'], mode='markers', marker=dict (size=12,color=colors,colorscale='Viridis', opacity=0.5,showscale=True) # opacity is transparency) data= [Trace01] fig=go.Figure (data=data,layout=layout) iplot (fig,filename='3d')

Thank you for your reading, the above is the content of "how to draw a chart with Python matplotlib plotly". After the study of this article, I believe you have a deeper understanding of how to draw a chart with Python matplotlib plotly, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Type ticket price number of people movies charts Chinese movies China learning content data graphs ratings multiple density objects namely ideas situations data sources articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info MariaDB macOS Redmi