python中plot函数参数_Python的 plot函数和绘图参数设置

python的plot函数参数很多,其中主要有:

plot([x], y, [fmt], data=None, **kwargs)

plot([x], y, [fmt], [x2], y2, [fmt2], ...,**kwargs)

Parameters----------x, y : array-like orscalar

The horizontal/vertical coordinates of the data points.*x* values are optional. If notgiven, they default to

``[0, ..., N-1]``.

Commonly, these parameters are arrays of length N. However,

scalars are supported as well (equivalent to an array with

constant value).

The parameters can also be2-dimensional. Then, the columns

represent separate data sets.

fmt : str, optional

A format string, e.g.‘ro‘ for red circles. See the *Notes*sectionfora full description of the format strings.

Format strings are just an abbreviationforquickly setting

basic line properties. All of theseandmore can also be

controlled by keyword arguments.

而在使用的时候,参数格式有:

1. fmt 参数:

**Format Strings**A format string consists of a partfor color, marker andline::

fmt= ‘[color][marker][line]‘

2. color 参数:

**Colors**The following color abbreviations are supported:============= ===============================character color============= ===============================``‘b‘`` blue

``‘g‘`` green

``‘r‘`` red

``‘c‘`` cyan

``‘m‘`` magenta

``‘y‘`` yellow

``‘k‘`` black

``‘w‘`` white============= ===============================If the coloristhe only part of the format string, you can

additionally use any `matplotlib.colors` spec, e.g. full names

(``‘green‘``) or hex strings (``‘#008000‘``).

3. marker 参数:

**Markers**

============= ===============================character description============= ===============================``‘.‘`` point marker

``‘,‘`` pixel marker

``‘o‘`` circle marker

``‘v‘`` triangle_down marker

``‘^‘`` triangle_up marker

``‘

``‘>‘`` triangle_right marker

``‘1‘`` tri_down marker

``‘2‘`` tri_up marker

``‘3‘`` tri_left marker

``‘4‘`` tri_right marker

``‘s‘`` square marker

``‘p‘`` pentagon marker

``‘*‘`` star marker

``‘h‘`` hexagon1 marker

``‘H‘`` hexagon2 marker

``‘+‘`` plus marker

``‘x‘`` x marker

``‘D‘`` diamond marker

``‘d‘`` thin_diamond marker

``‘|‘`` vline marker

``‘_‘`` hline marker============= ===============================

4. linestyle 参数:

**Line Styles**

============= ===============================character description============= ===============================``‘-‘`` solid line style

``‘--‘`` dashed line style

``‘-.‘`` dash-dot line style

``‘:‘`` dotted line style============= ===============================

6. 以下用一个例子来说明,可能更快一些:

importmatplotlib.pyplot as pltimportnumpy as np

fig= plt.figure(1)

x2= np.linspace(-0.2, 2, 10)

y2= x2 + 0.3plt.plot(x2, y2, color="red", linewidth=1.0, marker = ‘s‘, linestyle="--")# plt.plot(x2, y2, color="#ef5492", linewidth=2.0, marker = ‘s‘, linestyle="--") #也可#plt.plot(x2, y2, ‘rs--‘) #也可

#设置X轴标签

plt.xlabel(‘X坐标‘)#设置Y轴标签

plt.ylabel(‘Y坐标‘)

plt.title(‘test绘图函数‘)#设置图标#plt.legend(‘绘图值‘, loc=2, fontsize = 5)#The relative size of legend markers compared with the originally drawn ones.

plt.legend([‘绘图值‘], loc=‘upper left‘, markerscale = 0.5, fontsize = 10)#设置横轴的上下限

plt.xlim(-0.5, 2.5)#设置纵轴的上下限

plt.ylim(-0.5, 2.5)#设置横轴精准刻度

plt.xticks(np.arange(-0.5, 2.5, step=0.5))#设置纵轴精准刻度

plt.yticks(np.arange(-0.5, 2.5, step=0.5))#plt.annotate("(" + str(round(x[2],2)) +", "+ str(round(y[2],2)) +")", xy=(x[2], y[2]), fontsize=10, xycoords=‘data‘)

plt.annotate("({0},{1})".format(round(x2[2],2), round(y2[2],2)), xy=(x2[2], y2[2]), fontsize=10, xycoords=‘data‘)#xycoords=‘data‘ 以data值为基准#设置字体大小为 10

plt.text(round(x2[6],2), round(y2[6],2), "good point", fontdict={‘size‘: 10, ‘color‘: ‘red‘}) #fontdict设置文本字体#Add text to the axes.

plt.rcParams[‘font.sans-serif‘]=[‘SimHei‘] #用来正常显示中文标签

plt.rcParams[‘axes.unicode_minus‘]=False #用来正常显示负号

plt.savefig(‘test_xx.png‘, dpi=100, transparent=False)#dpi: The resolution in dots per inch#If *True*, the axes patches will all be transparent

plt.show()

47d35a0e57e5484012ba9eabe5afe14e.png

##

参考:

https://blog.csdn.net/u014636245/article/details/82799573

https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure

https://www.jianshu.com/p/78ba36dddad8

https://blog.csdn.net/u010852680/article/details/77770097

https://blog.csdn.net/u013634684/article/details/49646311

原文:https://www.cnblogs.com/qi-yuan-008/p/12588351.html

好的,很高兴为您解答有关Python绘图函数的问题。pandas.DataFrame.plot() 是一个常用的 Python 绘图函数,它可以对 DataFrame 的数据进行可视化展示,非常方便和实用。下面我将为您详细介绍这个函数。 pandas.DataFrame.plot() 函数是 pandas 库的一个函数,它可以用来绘制 DataFrame 的数据。这个函数可以支持多种类型的图形,包括线性图、散点图、柱状图、饼图等。在使用这个函数之前,需要先引入 pandas 和 matplotlib 库,例如: ```python import pandas as pd import matplotlib.pyplot as plt ``` 然后,我们就可以使用 DataFrame.plot() 函数来绘制图形了。这个函数的基本语法如下: ```python DataFrame.plot(kind='line', x=None, y=None, ax=None, subplots=False, figsize=None, title=None) ``` 其,kind 参数表示要绘制的图形类型,x 和 y 参数分别表示数据要作为 X 轴和 Y 轴的列名称,ax 参数用于指定绘图的坐标轴,subplots 参数表示是否将每个列绘制到单独的子图,figsize 参数用于指定图形的大小,title 参数表示图形的标题。 下面给出几个示例: ```python # 示例1:绘制线性图 data = {'x': [1, 2, 3, 4, 5], 'y': [2, 4, 6, 8, 10]} df = pd.DataFrame(data) df.plot(kind='line', x='x', y='y') plt.show() # 示例2:绘制散点图 data = {'x': [1, 2, 3, 4, 5], 'y': [2, 4, 6, 8, 10]} df = pd.DataFrame(data) df.plot(kind='scatter', x='x', y='y') plt.show() # 示例3:绘制柱状图 data = {'x': ['A', 'B', 'C', 'D', 'E'], 'y': [2, 4, 6, 8, 10]} df = pd.DataFrame(data) df.plot(kind='bar', x='x', y='y') plt.show() ``` 以上就是 pandas.DataFrame.plot() 函数的基本介绍和示例。希望对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值