matplotlib

50个最有价值的数据可视化图表

∥☆過路亽.° 提交于 2021-01-19 00:12:49
文总结了在数据分析和可视化中最有用的 50 个 Matplotlib 图表。这些图表列表允许您使用 python 的 matplotlib 和 seaborn 库选择要显示的可视化对象。 这些图表根据可视化目标的 7 个不同情景进行分组。 例如,如果要想象两个变量之间的关系,请查看“关联”部分下的图表。或者,如果您想要显示值如何随时间变化,请查看“变化”部分,依此类推。 有效图表的重要特征: 在不歪曲事实的情况下传达正确和必要的信息。 设计简单,您不必太费力就能理解它。 从审美角度支持信息而不是掩盖信息。 信息没有超负荷。 01 关联(Correlation) 关联图表用于可视化 2 个或更多变量之间的关系。也就是说, 一个变量如何相对于另一个变化。 1. 散点图(Scatter plot) 散点图是用于研究两个变量之间关系的经典的和基本的图表。如果数据中有多个组,则可能需要以不同颜色可视化每个组。您可以使用 plt.scatterplot() 方便地执行此操作。 2. 带边界的气泡图(Bubble plot with Encircling) 有时,您希望在边界内显示一组点以强调其重要性。在这个例子中,你从数据框中获取记录,并用 encircle() 来使边界显示出来。 3. 带线性回归最佳拟合线的散点图(Scatter plot with linear regression

How to fill color by groups in histogram using Matplotlib?

孤者浪人 提交于 2021-01-18 07:15:00
问题 I know how to do this in R and have provided a code for it below. I want to know how can I do something similar to the below mentioned in Python Matplotlib or using any other library library(ggplot2) ggplot(dia[1:768,], aes(x = Glucose, fill = Outcome)) + geom_bar() + ggtitle("Glucose") + xlab("Glucose") + ylab("Total Count") + labs(fill = "Outcome") 回答1: Please consider the following example, which uses seaborn 0.11.1. import pandas as pd import numpy as np import seaborn as sns import

How to fill color by groups in histogram using Matplotlib?

北城余情 提交于 2021-01-18 07:06:30
问题 I know how to do this in R and have provided a code for it below. I want to know how can I do something similar to the below mentioned in Python Matplotlib or using any other library library(ggplot2) ggplot(dia[1:768,], aes(x = Glucose, fill = Outcome)) + geom_bar() + ggtitle("Glucose") + xlab("Glucose") + ylab("Total Count") + labs(fill = "Outcome") 回答1: Please consider the following example, which uses seaborn 0.11.1. import pandas as pd import numpy as np import seaborn as sns import

在python3下使用OpenCV 显示图像

末鹿安然 提交于 2021-01-18 06:55:03
在Python3下用使用OpenCV比在C,C++里开发不止快捷一点点, 原型开发的时候蛮有用. 这里用的OpenCV 加载图片, 用的imshow画图 # -*- coding: utf-8 -*- import cv2 # from matplotlib import pyplot as plt from pylab import * # 添加中文字体支持 from matplotlib.font_manager import FontProperties font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc",size = 14) # 载入图像 im = cv2.imread('window.png') # 显示原始图像 fig = plt.figure() subplot(121) plt.gray() im2 = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) # OpenCV采用BGR排列顺序,需要转换一下. imshow(im2) title(u'彩色图', fontproperties= font) axis('off') # 显示灰度化图像 # 颜色空间转换 gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) plt.subplot(122)

combine different seaborn facet grids into single plot

末鹿安然 提交于 2021-01-18 05:59:12
问题 I have three different data sets where I produce a facetplot, each a = sns.FacetGrid(data1, col="overlap", hue="comp") a = (g.map(sns.kdeplot, "val",bw=0.8)) b = sns.FacetGrid(data2, col="overlap", hue="comp") b = (g.map(sns.kdeplot, "val",bw=0.8)) c = sns.FacetGrid(data3, col="overlap", hue="comp") c = (g.map(sns.kdeplot, "val",bw=0.8)) Each of those plots has three subplots in one row, so in total I have nine plots. I would like to combine these plots, in a subplots setting like this f,

Extract coordinates enclosed by a matplotlib patch.

谁说我不能喝 提交于 2021-01-18 04:35:42
问题 I have created an ellipse using matplotlib.patches.ellipse as shown below: patch = mpatches.Ellipse(center, major_ax, minor_ax, angle_deg, fc='none', ls='solid', ec='g', lw='3.') What I want is a list of all the integer coordinates enclosed inside this patch. I.e. If I was to plot this ellipse along with every integer point on the same grid, how many of those points are enclosed in the ellipse? I have tried seeing if I can extract the equation of the ellipse so I can loop through each point

How to plot a bar graph from a pandas series?

冷暖自知 提交于 2021-01-17 17:37:17
问题 Consider my series as below: First column is article_id and the second column is frequency count. article_id 1 39 2 49 3 187 4 159 5 158 ... 16947 14 16948 7 16976 2 16977 1 16978 1 16980 1 Name: article_id, dtype: int64 I got this series from a dataframe with the following command: logs.loc[logs['article_id'] <= 17029].groupby('article_id')['article_id'].count() logs is the dataframe here and article_id is one of the columns in it. How do I plot a bar chart(using Matlplotlib) such that the

How to plot a bar graph from a pandas series?

允我心安 提交于 2021-01-17 17:34:14
问题 Consider my series as below: First column is article_id and the second column is frequency count. article_id 1 39 2 49 3 187 4 159 5 158 ... 16947 14 16948 7 16976 2 16977 1 16978 1 16980 1 Name: article_id, dtype: int64 I got this series from a dataframe with the following command: logs.loc[logs['article_id'] <= 17029].groupby('article_id')['article_id'].count() logs is the dataframe here and article_id is one of the columns in it. How do I plot a bar chart(using Matlplotlib) such that the

How to plot a bar graph from a pandas series?

拟墨画扇 提交于 2021-01-17 17:33:06
问题 Consider my series as below: First column is article_id and the second column is frequency count. article_id 1 39 2 49 3 187 4 159 5 158 ... 16947 14 16948 7 16976 2 16977 1 16978 1 16980 1 Name: article_id, dtype: int64 I got this series from a dataframe with the following command: logs.loc[logs['article_id'] <= 17029].groupby('article_id')['article_id'].count() logs is the dataframe here and article_id is one of the columns in it. How do I plot a bar chart(using Matlplotlib) such that the

How do I extend the margin at the bottom of a figure in Matplotlib?

坚强是说给别人听的谎言 提交于 2021-01-16 12:30:31
问题 The following screenshot shows my x-axis. I added some labels and rotated them by 90 degrees in order to better read them. However, pyplot truncates the bottom such that I'm not able to completely read the labels. How do I extend the bottom margin in order to see the complete labels? 回答1: Two retroactive ways: fig, ax = plt.subplots() # ... fig.tight_layout() Or fig.subplots_adjust(bottom=0.2) # or whatever Here's a subplots_adjust example: http://matplotlib.org/examples/pylab_examples