python Matplotlib可视化(基础知识)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Matplotlib可视化(基础知识)相关的知识,希望对你有一定的参考价值。

# Basic lineplot using matplotlib
women_degrees = pd.read_csv('percent-bachelors-degrees-women-usa.csv')
plt.plot(women_degrees['Year'], women_degrees['Biology']) # Defining x and y axis
plt.show()

# Lineplot with 2 data series
fig, ax = plt.subplots() # This is needed only when ".ax" is used
plt.plot(women_degrees['Year'], women_degrees['Biology'], c='blue', label='Women', linewidth=3) # Setting color, label and line width of the line plot
plt.plot(women_degrees['Year'], 100-women_degrees['Biology'], c='green', label='Men', linewidth=3)
plt.legend(loc='upper right')
plt.title('Percentage of Biology Degrees Awarded By Gender')
ax.tick_params(bottom="off", top="off", left="off", right="off") # Turning axes ticks off on the different sides of the chart
ax.set_xlim(1968, 2011) # Sets the limmit of the x-axis
ax.set_ylim(0, 100) # Sets the limit of the y-axis
plt.show()

# Labels can be added to the chart to replace legend
ax.text(2005, 62, "Men") # x, y coordinates and string
ax.text(2001, 35, "Women") # x, y coordinates and string for the 2nd dataseries

# Making a stacked barplot
df[["2FL [g/kg]", "DFL [g/kg]"]].plot.bar(stacked=True)

以上是关于python Matplotlib可视化(基础知识)的主要内容,如果未能解决你的问题,请参考以下文章

Python之matplotlib基础

Python--matplotlib绘图可视化知识点整理

Python--matplotlib绘图可视化知识点整理

Python数据科学快速入门系列 | 06Matplotlib数据可视化基础入门

Matplotlib数据可视化相关知识及画图例子展示

Matplotlib数据可视化相关知识及画图例子展示