21 數(shù)據(jù)分析 09-15

01-數(shù)據(jù)分析介紹和環(huán)境安裝

conda: data science package & environment manager
創(chuàng)建環(huán)境:
conda creat -- name python3 python=3
切換環(huán)境:
windows: activate python3
linux/macos: source activate python3
官方地址:https://www.anaconda.com/download

02-matplotlib折線圖

matplotlib是python的一個繪圖庫鼻弧,與numpy、pandas共享數(shù)據(jù)科學(xué)三劍客的美譽(yù)顷链,
Python--Matplotlib(基本用法)
Matplotlib入門詳細(xì)教程
Pandas入門詳細(xì)教程

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環(huán)境下:
使用matplotlib報(bào)錯

#1.在導(dǎo)入pyplot之前.需要輸入如下步驟:
  import matplotlib as mpl
  mpl.use('Agg')           或   mpl.use('TkAgg')
#加上述兩句后,程序不報(bào)錯泣侮,但無顯示
  import matplotlib
  print(matplotlib.get_backend())
#將得到的字符串結(jié)果替換mlp.use('Agg')中Agg'即可

21-02-02 matplotlib的基礎(chǔ)繪圖和調(diào)整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 ……
#設(shè)置圖片大小
plt.figure(figsize=(10,5),dpi=80)
#設(shè)置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)

#調(diào)整x軸的刻度
_xtick_labels = ["10點(diǎn){}分".format(i) for i in range(60)]
_xtick_labels += ["11點(diǎn){}分".format(i) for i in range(60)]
#取步長添寺,數(shù)字和字符串一一對應(yīng),數(shù)據(jù)的長度一樣
plt.xticks(list(x)[::3],_xtick_labels[::3],rotation=45,fontproperties=my_font) #rotaion旋轉(zhuǎn)的度數(shù)

#添加描述信息
plt.xlabel("時間",fontproperties=my_font)
plt.ylabel("溫度 單位(℃)",fontproperties=my_font)
plt.title("10點(diǎn)到12點(diǎn)每分鐘的氣溫變化情況",fontproperties=my_font)

E:\BaiduNetdiskDownload\Python\Python就業(yè)班\21 數(shù)據(jù)分析\03-matplotlib常用統(tǒng)計(jì)圖

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.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末网杆,一起剝皮案震驚了整個濱河市吃环,隨后出現(xiàn)的幾起案子也颤,更是在濱河造成了極大的恐慌,老刑警劉巖郁轻,帶你破解...
    沈念sama閱讀 211,123評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件歇拆,死亡現(xiàn)場離奇詭異,居然都是意外死亡范咨,警方通過查閱死者的電腦和手機(jī)故觅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評論 2 384
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來渠啊,“玉大人输吏,你說我怎么就攤上這事√骝龋” “怎么了贯溅?”我有些...
    開封第一講書人閱讀 156,723評論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長躲查。 經(jīng)常有香客問我它浅,道長,這世上最難降的妖魔是什么镣煮? 我笑而不...
    開封第一講書人閱讀 56,357評論 1 283
  • 正文 為了忘掉前任姐霍,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘镊折。我一直安慰自己胯府,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評論 5 384
  • 文/花漫 我一把揭開白布恨胚。 她就那樣靜靜地躺著骂因,像睡著了一般。 火紅的嫁衣襯著肌膚如雪赃泡。 梳的紋絲不亂的頭發(fā)上寒波,一...
    開封第一講書人閱讀 49,760評論 1 289
  • 那天,我揣著相機(jī)與錄音升熊,去河邊找鬼俄烁。 笑死,一個胖子當(dāng)著我的面吹牛僚碎,可吹牛的內(nèi)容都是我干的猴娩。 我是一名探鬼主播阴幌,決...
    沈念sama閱讀 38,904評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼勺阐,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了矛双?” 一聲冷哼從身側(cè)響起渊抽,我...
    開封第一講書人閱讀 37,672評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎议忽,沒想到半個月后懒闷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,118評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡栈幸,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評論 2 325
  • 正文 我和宋清朗相戀三年愤估,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片速址。...
    茶點(diǎn)故事閱讀 38,599評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡玩焰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出芍锚,到底是詐尸還是另有隱情昔园,我是刑警寧澤,帶...
    沈念sama閱讀 34,264評論 4 328
  • 正文 年R本政府宣布并炮,位于F島的核電站默刚,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏逃魄。R本人自食惡果不足惜荤西,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧皂冰,春花似錦店展、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,731評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至舶胀,卻和暖如春概说,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背嚣伐。 一陣腳步聲響...
    開封第一講書人閱讀 31,956評論 1 264
  • 我被黑心中介騙來泰國打工糖赔, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人轩端。 一個月前我還...
    沈念sama閱讀 46,286評論 2 360
  • 正文 我出身青樓放典,卻偏偏與公主長得像,于是被迫代替她去往敵國和親基茵。 傳聞我的和親對象是個殘疾皇子奋构,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評論 2 348

推薦閱讀更多精彩內(nèi)容