21 数据分析 09-15

01-数据分析介绍和环境安装

conda: data science package & environment manager
创建环境:
conda creat -- name python3 python=3
切换环境:
windows: activate python3
linux/macos: source activate python3
官方地址:https://www.anaconda.com/download

02-matplotlib折线图

matplotlib是python的一个绘图库,与numpy、pandas共享数据科学三剑客的美誉,
Python--Matplotlib(基本用法)
Matplotlib入门详细教程
Pandas入门详细教程

from matplotlib import pyplot as plt
x = range(2,26,2)
y =[15,13,14.5,17,20,25,26,26,24,22,18,15]
plt.plot(x,y)
plt.show()

win7环境下:
使用matplotlib报错

#1.在导入pyplot之前.需要输入如下步骤:
  import matplotlib as mpl
  mpl.use('Agg')           或   mpl.use('TkAgg')
#加上述两句后,程序不报错,但无显示
  import matplotlib
  print(matplotlib.get_backend())
#将得到的字符串结果替换mlp.use('Agg')中Agg'即可

21-02-02 matplotlib的基础绘图和调整x轴的刻度


matplotlib.pyplot **kwargs Text text(x, y, s[, fontdict])

#matplotlib.pyplot方法 figure xticks xlabel xlim xscale
subplot subplots axes
plot bar hist
**kwargs :rotation alpha backgroundcolor color fontsize or size fontweight or weight ……
#设置图片大小
plt.figure(figsize=(10,5),dpi=80)
#设置x轴的刻度
_xtick_labels = [i/2 for i in range(4,49)]
plt.xticks(range(15,40))
plt.yticks(range(min(y),max(y)+1))
#保存
plt.savefig("./t1.png")      #*.svg 是矢量图格式

----------------------
my_font = font_manager.FontProperties(fname=r"e:\python\ttc\msgothic.ttc")
x = range(0,120)
y = [random.randint(20,35) for i in range(120)]
plt.figure(figsize=(20,8),dpi=80)
plt.plot(x,y)

#调整x轴的刻度
_xtick_labels = ["10点{}分".format(i) for i in range(60)]
_xtick_labels += ["11点{}分".format(i) for i in range(60)]
#取步长,数字和字符串一一对应,数据的长度一样
plt.xticks(list(x)[::3],_xtick_labels[::3],rotation=45,fontproperties=my_font) #rotaion旋转的度数

#添加描述信息
plt.xlabel("时间",fontproperties=my_font)
plt.ylabel("温度 单位(℃)",fontproperties=my_font)
plt.title("10点到12点每分钟的气温变化情况",fontproperties=my_font)

E:\BaiduNetdiskDownload\Python\Python就业班\21 数据分析\03-matplotlib常用统计图

a


Function Description
acorr Plot the autocorrelation of x.
angle_spectrum Plot the angle spectrum.
annotate Annotate the point xy with text text.
arrow Add an arrow to the Axes.
autoscale Autoscale the axis view to the data (toggle).
axes Add an axes to the current figure and make it the current axes.
axhline Add a horizontal line across the axis.
axhspan Add a horizontal span (rectangle) across the Axes.
axis Convenience method to get or set some axis properties.
axline Add an infinitely long straight line.
axvline Add a vertical line across the Axes.
axvspan Add a vertical span (rectangle) across the Axes.
bar Make a bar plot.
bar_label Label a bar plot.
barbs Plot a 2D field of barbs.
barh Make a horizontal bar plot.
box Turn the axes box on or off on the current axes.
boxplot Make a box and whisker plot.
broken_barh Plot a horizontal sequence of rectangles.
cla Clear the current axes.
clabel Label a contour plot.
clf Clear the current figure.
clim Set the color limits of the current image.
close Close a figure window.
cohere Plot the coherence between x and y.
colorbar Add a colorbar to a plot.
contour Plot contour lines.
contourf Plot filled contours.
csd Plot the cross-spectral density.
delaxes Remove an Axes (defaulting to the current axes) from its figure.
draw Redraw the current figure.
draw_if_interactive Redraw the current figure if in interactive mode.
errorbar Plot y versus x as lines and/or markers with attached errorbars.
eventplot Plot identical parallel lines at the given positions.
figimage Add a non-resampled image to the figure.
figlegend Place a legend on the figure.
fignum_exists Return whether the figure with the given id exists.
figtext Add text to figure.
figure Create a new figure, or activate an existing figure.
fill Plot filled polygons.
fill_between Fill the area between two horizontal curves.
fill_betweenx Fill the area between two vertical curves.
findobj Find artist objects.
gca Get the current Axes, creating one if necessary.
gcf Get the current figure.
gci Get the current colorable artist.
get Return the value of an Artist's property, or print all of them.
get_figlabels Return a list of existing figure labels.
get_fignums Return a list of existing figure numbers.
getp Return the value of an Artist's property, or print all of them.
grid Configure the grid lines.
hexbin Make a 2D hexagonal binning plot of points x, y.
hist Plot a histogram.
hist2d Make a 2D histogram plot.
hlines Plot horizontal lines at each y from xmin to xmax.
imread Read an image from a file into an array.
imsave Save an array as an image file.
imshow Display data as an image, i.e., on a 2D regular raster.
install_repl_displayhook Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.
ioff Disable interactive mode.
ion Enable interactive mode.
isinteractive Return whether plots are updated after every plotting command.
legend Place a legend on the Axes.
locator_params Control behavior of major tick locators.
loglog Make a plot with log scaling on both the x and y axis.
magnitude_spectrum Plot the magnitude spectrum.
margins Set or retrieve autoscaling margins.
matshow Display an array as a matrix in a new figure window.
minorticks_off Remove minor ticks from the axes.
minorticks_on Display minor ticks on the axes.
new_figure_manager Create a new figure manager instance.
pause Run the GUI event loop for interval seconds.
pcolor Create a pseudocolor plot with a non-regular rectangular grid.
pcolormesh Create a pseudocolor plot with a non-regular rectangular grid.
phase_spectrum Plot the phase spectrum.
pie Plot a pie chart.
plot Plot y versus x as lines and/or markers.
plot_date Plot co-ercing the axis to treat floats as dates.
polar Make a polar plot.
psd Plot the power spectral density.
quiver Plot a 2D field of arrows.
quiverkey Add a key to a quiver plot.
rc Set the current rcParams.
rc_context Return a context manager for temporarily changing rcParams.
rcdefaults Restore the rcParams from Matplotlib's internal default style.
rgrids Get or set the radial gridlines on the current polar plot.
savefig Save the current figure.
sca Set the current Axes to ax and the current Figure to the parent of ax.
scatter A scatter plot of y vs.
sci Set the current image.
semilogx Make a plot with log scaling on the x axis.
semilogy Make a plot with log scaling on the y axis.
set_cmap Set the default colormap, and applies it to the current image if any.
setp Set one or more properties on an Artist, or list allowed values.
show Display all open figures.
specgram Plot a spectrogram.
spy Plot the sparsity pattern of a 2D array.
stackplot Draw a stacked area plot.
stairs A stepwise constant function as a line with bounding edges or a filled plot.
stem Create a stem plot.
step Make a step plot.
streamplot Draw streamlines of a vector flow.
subplot Add an Axes to the current figure or retrieve an existing Axes.
subplot2grid Create a subplot at a specific location inside a regular grid.
subplot_mosaic Build a layout of Axes based on ASCII art or nested lists.
subplot_tool Launch a subplot tool window for a figure.
subplots Create a figure and a set of subplots.
subplots_adjust Adjust the subplot layout parameters.
suptitle Add a centered suptitle to the figure.
switch_backend Close all open figures and set the Matplotlib backend.
table Add a table to an Axes.
text Add text to the Axes.
thetagrids Get or set the theta gridlines on the current polar plot.
tick_params Change the appearance of ticks, tick labels, and gridlines.
ticklabel_format Configure the ScalarFormatter used by default for linear axes.
tight_layout Adjust the padding between and around subplots.
title Set a title for the Axes.
tricontour Draw contour lines on an unstructured triangular grid.
tricontourf Draw contour regions on an unstructured triangular grid.
tripcolor Create a pseudocolor plot of an unstructured triangular grid.
triplot Draw a unstructured triangular grid as lines and/or markers.
twinx Make and return a second axes that shares the x-axis.
twiny Make and return a second axes that shares the y-axis.
uninstall_repl_displayhook Uninstall the matplotlib display hook.
violinplot Make a violin plot.
vlines Plot vertical lines at each x from ymin to ymax.
xcorr Plot the cross correlation between x and y.
xkcd Turn on xkcd sketch-style drawing mode.
xlabel Set the label for the x-axis.
xlim Get or set the x limits of the current axes.
xscale Set the x-axis scale.
xticks Get or set the current tick locations and labels of the x-axis.
ylabel Set the label for the y-axis.
ylim Get or set the y-limits of the current axes.
yscale Set the y-axis scale.
yticks Get or set the current tick locations and labels of the y-axis.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,186评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,858评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,620评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,888评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,009评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,149评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,204评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,956评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,385评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,698评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,863评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,544评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,185评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,899评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,141评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,684评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,750评论 2 351

推荐阅读更多精彩内容