绘图

2017-06-14  本文已影响0人  maocy

地图+爬虫
https://zhuanlan.zhihu.com/p/21883516

颜色 线条

k w r y g c b m
http://www.cnblogs.com/darkknightzh/p/6117528.html

date_parse=lambda dates: pd.datetime.strptime(dates,'%Y/%M/%D %H:%M%S)
df_train=pd.read.csv('',parse_dates=[0],date_parser=date_parse)

df_train['date']=pd.to_datetime(df_train['stime'].apply(lambda x:x.date()))
df_train['time']=pd.to_datetime(df_train['stime'].apply(lambda x:x.time()))

#时间序列作图
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates


date_parse = lambda dates: pd.datetime.strptime(dates, '%Y-%m-%d %H:%M:%S')
df_train = pd.read_csv('C:/Users/user/Documents/gzyd/LTE2.csv', parse_dates=[0], date_parser=date_parse)



eNodeB_171312=df_train[df_train.eNodeB==171312]
start_date = pd.Timestamp('2017-4-20')
end_date = pd.Timestamp('2017-4-21')
eNodeB_171312_420=eNodeB_171312[(eNodeB_171312.stime>=start_date)&(eNodeB_171312.stime<end_date)]
eNodeB_171312_420=eNodeB_171312_420.sort_values(["stime"],ascending=True)


plt.style.use('ggplot')

fig, ax = plt.subplots(1)
fig.autofmt_xdate()
plt.plot(eNodeB_171312_420['stime'], eNodeB_171312_420['max_user'], 'r')
xfmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(xfmt)
plt.xticks(pd.date_range(min(eNodeB_171312_420['stime']),max(eNodeB_171312_420['stime']),freq='60min'))
#plt.xticks(rotation=90)
#ax.xaxis.set_minor_locator(hours)

plt.show()
plt.style.use('ggplot')
plt.plot(data_num1['date_string'],data_num1_minmax['C12'],'g*:',label='C12')
plt.plot(data_num1['date_string'],data_num1_minmax['C40'],'bo:',label='C40')
plt.plot(data_num1['date_string'],data_num1_minmax['U19'],'r:',label='U19')
plt.legend()

颜色齐全

[python中matplotlib的颜色及线条控制] (http://www.cnblogs.com/darkknightzh/p/6117528.html)
python使用matplotlib绘制折线图教程(点 颜色等)
http://www.jb51.net/article/104916.htm

图例大小 位置 颜色

https://www.zhihu.com/question/45028370/answer/98194654

import numpy as np
import matplotlib.pyplot as plt

# Make some fake data.
a = b = np.arange(0, 3, .02)
c = np.exp(a)
d = c[::-1]

# Create plots with pre-defined labels.
plt.plot(a, c, 'k--', label='Model length')
plt.plot(a, d, 'k:', label='Data length')
plt.plot(a, c + d, 'k', label='Total message length')

legend = plt.legend(loc='upper center', title='Test', shadow=True, fontsize='x-large')

# Put a nicer background color on the legend.
legend.get_frame().set_facecolor('#00FFCC')
legend.get_title().set_fontsize(fontsize = 20)
# 不仅可以设置字体大小,还可以设置什么字体,因为legend.get_title()返回的是一个'Text'属性
# 的对像,时刻不要忘记Matplotlib面向对像的画图方式啊
plt.show()
python matplotlib绘图设置坐标轴刻度、文本
http://blog.csdn.net/fortware/article/details/51934814

from pylab import *  
from matplotlib.ticker import MultipleLocator, FormatStrFormatter  
  
xmajorLocator   = MultipleLocator(20) #将x主刻度标签设置为20的倍数  
xmajorFormatter = FormatStrFormatter('%1.1f') #设置x轴标签文本的格式  
xminorLocator   = MultipleLocator(5) #将x轴次刻度标签设置为5的倍数  
  
ymajorLocator   = MultipleLocator(0.5) #将y轴主刻度标签设置为0.5的倍数  
ymajorFormatter = FormatStrFormatter('%1.1f') #设置y轴标签文本的格式  
yminorLocator   = MultipleLocator(0.1) #将此y轴次刻度标签设置为0.1的倍数  
  
t = arange(0.0, 100.0, 1)  
s = sin(0.1*pi*t)*exp(-t*0.01)  
  
ax = subplot(111) #注意:一般都在ax中设置,不再plot中设置  
plot(t,s,'--b*')  
  
#设置主刻度标签的位置,标签文本的格式  
ax.xaxis.set_major_locator(xmajorLocator)  
ax.xaxis.set_major_formatter(xmajorFormatter)  
  
ax.yaxis.set_major_locator(ymajorLocator)  
ax.yaxis.set_major_formatter(ymajorFormatter)  
  
#显示次刻度标签的位置,没有标签文本  
ax.xaxis.set_minor_locator(xminorLocator)  
ax.yaxis.set_minor_locator(yminorLocator)  
  
ax.xaxis.grid(True, which='major') #x坐标轴的网格使用主刻度  
ax.yaxis.grid(True, which='minor') #y坐标轴的网格使用次刻度  
  
show()  

刻度显示字符/改变

import matplotlib.pyplot as plt

plt.style.use('ggplot')
fx,ax = plt.subplots(1)
ax.plot(data_index['cci601'],'k*:',label='C12')
ticks = ax.set_xticks(range(26))
labels = ax.set_xticklabels(data_index['name'],fontsize = 'small')
ax.set_ylabel('signal quality')
plt.ylim(-0.6,1.5)
plt.show()

绘图显示中文

Matplotlib输出中文显示问题
https://my.oschina.net/u/1180306/blog/279818

缺失值导致绘图 ValueError: max must be larger than min in range parameter.

data_20W_U6=data_20W['U6'].dropna()
plt.hist(data_20W_U6,50, alpha=0.9, color='blue')

seaborn
http://blog.csdn.net/kevinelstri/article/details/52938604

上一篇下一篇

猜你喜欢

热点阅读