Drawing of graphics in python

零到壹度
Release: 2018-04-19 15:42:39
Original
2940 people have browsed it

The example in this article describes the drawing of graphics in Python. Share it with everyone for your reference, the details are as follows:

1. Add data labels to the graph

plt.plot(datat.index,datat)
plt.xlabel('index', fontsize=15)
plt.legend(['t_bottom','t_top'],loc = 'upper_right',fontsize = 10)
plt.show()
Copy after login

2. Set the labels On the far right

plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
Copy after login



3, a box appears when displaying Chinese fonts

# coding: UTF-8
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号#有中文出现的情况,需要u'内容
Copy after login

4. Draw a heat map

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
d ={'1':[0.87,0.95],'2':[0.86,0.91],'3':[0.86,0.93],'4':[0.86,0.92],'5':[0.86,0.93]}
df = pd.DataFrame(d,index = [2,1])
df
### annot是表示显示方块代表的数值出来 cmap颜色
sns.heatmap(df,annot = True,cmap="YlGnBu")
plt.show()
Copy after login

5. Draw a scatter plot and overlap multiple graphs


import matplotlib.pyplot as plt
import seaborn as sns
color = sns.color_palette()
sns.set_style('darkgrid')
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号#有中文出现的情况,需要u'内容'

plt.figure(figsize=[9,6])
plt.plot(datat.index,datat_.t_bottom,color = 'r')
plt.plot(datat.index,datat_.t_top,color = 'c')
plt.scatter(datat.index,datat_.bottom,marker='.',c='g')
plt.scatter(datat.index,datat_.top,marker='.',c='b')
plt.legend(('t_bottom','t_top','noise_bottom','noise_top'),loc = 'upper right',fontsize=15)
plt.xlabel('index', fontsize=15)
plt.ylabel(u'温度', fontsize=15)
#plt.legend(['t_bottom','t_top'],loc = 'upper_right',fontsize = 10)
plt.show()
Copy after login


##6. Drawing color

color =

greenredcyan##'w'
character color
<span class="pre">'b'</span> blue
##'g'<span class="pre"></span>
'r'<span class="pre"></span>
'c'<span class="pre"></span>
##'m'<span class="pre"></span>magenta
'y'<span class="pre"></span>yellow
'k'<span class="pre"></span>black
<span class="pre"></span>white

##Related recommendations:

Draw custom graphics

CSS3 draws various graphics

Use the turtle library in python to draw graphics

Drawing of iOS basic graphics

The above is the detailed content of Drawing of graphics in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!