matplotlib

Rotate xtick labels in seaborn boxplot?

佐手、 提交于 2021-01-20 14:54:15
问题 I have a question that is basically the same as a question back from 2014 (see here). However, my script still throws an error. Here is what I do: I have a pandas dataframe with a few columns. I plot a simple boxplot comparison. g = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) g.set_xticklabels(rotation=30) The graph looks like this: I'd like to rotate the x-labels by 30 degrees. Hence I use g.set_xticklabels(rotation=30) . However, I get the following error: set_xticklabels

让图形变得精致:seaborn绘图基础

♀尐吖头ヾ 提交于 2021-01-20 09:08:07
1、seaborn的优点 它简化了复杂数据集的表示; 可以轻松构建复杂的可视化,简洁的控制matplotlib图形样式与几个内置主题; seaborn不可以替代matplotlib,而是matplotlib的很好补充; 2、seaborn的官网 学习某个知识点,最好的东西就是照着官网的提示学习,因为官网里面的知识点,够完整、够全面。seaborn的官网链接:http://seaborn.pydata.org 3、seaborn的作者介绍 4、seaborn的缩写为什么是sns,而不是sbn? sns的使用来自于一个内部笑话,与美剧The West Wing有关。这部剧里有一个人物,名叫Samual Norman Seaborn,首字母简写为sns,因此最终简写为sns。 5、seaborn与matplotlib的关系? seaborn是matplotlib的更高级的封装。因此学习seaborn之前,首先要知道matplotlib的绘图原理。 我们知道,使用matplotlib绘图,需要调节大量的绘图参数,需要记忆的东西很多。而seaborn基于matplotlib做了更高级的封装,使得绘图更加容易,它不需要了解大量的底层参数,就可以绘制出很多比较精致的图形。不仅如此,seaborn还兼容numpy、pandas数据结构,在组织数据上起了很大作用

Stop gif image from repeating in matplotlib

て烟熏妆下的殇ゞ 提交于 2021-01-20 07:07:09
问题 I searched for other similar questions but that didn't solve my problem. Below is a simple code that generates an animation in the form of a gif image in matplotlib: import numpy as np import matplotlib.pylab as plt import matplotlib.animation as anm fig = plt.figure() def draw(i): x = np.linspace(0, 5, num = 1000) y = np.sin(x-i*0.1) plt.clf() plt.plot(x, y, 'r-') anim = anm.FuncAnimation(fig, draw, frames = 10, interval = 500, repeat = False) anim.save('test.gif', fps = 1, writer =

Stop gif image from repeating in matplotlib

谁都会走 提交于 2021-01-20 07:06:49
问题 I searched for other similar questions but that didn't solve my problem. Below is a simple code that generates an animation in the form of a gif image in matplotlib: import numpy as np import matplotlib.pylab as plt import matplotlib.animation as anm fig = plt.figure() def draw(i): x = np.linspace(0, 5, num = 1000) y = np.sin(x-i*0.1) plt.clf() plt.plot(x, y, 'r-') anim = anm.FuncAnimation(fig, draw, frames = 10, interval = 500, repeat = False) anim.save('test.gif', fps = 1, writer =

Matplotlib: imshow with second y axis

混江龙づ霸主 提交于 2021-01-20 04:17:56
问题 I'm trying to plot a two-dimensional array in matplotlib using imshow(), and overlay it with a scatterplot on a second y axis. oneDim = np.array([0.5,1,2.5,3.7]) twoDim = np.random.rand(8,4) plt.figure() ax1 = plt.gca() ax1.imshow(twoDim, cmap='Purples', interpolation='nearest') ax1.set_xticks(np.arange(0,twoDim.shape[1],1)) ax1.set_yticks(np.arange(0,twoDim.shape[0],1)) ax1.set_yticklabels(np.arange(0,twoDim.shape[0],1)) ax1.grid() #This is the line that causes problems ax2 = ax1.twinx()

Matplotlib: imshow with second y axis

时光总嘲笑我的痴心妄想 提交于 2021-01-20 04:15:54
问题 I'm trying to plot a two-dimensional array in matplotlib using imshow(), and overlay it with a scatterplot on a second y axis. oneDim = np.array([0.5,1,2.5,3.7]) twoDim = np.random.rand(8,4) plt.figure() ax1 = plt.gca() ax1.imshow(twoDim, cmap='Purples', interpolation='nearest') ax1.set_xticks(np.arange(0,twoDim.shape[1],1)) ax1.set_yticks(np.arange(0,twoDim.shape[0],1)) ax1.set_yticklabels(np.arange(0,twoDim.shape[0],1)) ax1.grid() #This is the line that causes problems ax2 = ax1.twinx()

Matplotlib plt.xlabel() vs ax.set_xlabel()

好久不见. 提交于 2021-01-19 08:27:19
问题 I am using some code that uses the singleton-version of matplotlib in Python, i.e. it has calls like plt.figure() ... plt.xlabel("abc") I am trying to convert it to the functional/memory-less version: fig,ax = plt.subplots() ... ax.set_xlabel("abc") A couple questions: Is there an option to set the xlabel of an axes directly? Something like ax.xlabel = "xlabel string" ? From the documentation, it seems like this is not possible. (not even a private attribute we can set) Or is it always

Matplotlib plt.xlabel() vs ax.set_xlabel()

懵懂的女人 提交于 2021-01-19 08:23:16
问题 I am using some code that uses the singleton-version of matplotlib in Python, i.e. it has calls like plt.figure() ... plt.xlabel("abc") I am trying to convert it to the functional/memory-less version: fig,ax = plt.subplots() ... ax.set_xlabel("abc") A couple questions: Is there an option to set the xlabel of an axes directly? Something like ax.xlabel = "xlabel string" ? From the documentation, it seems like this is not possible. (not even a private attribute we can set) Or is it always

How do you make the x-axis pass through (0,0) with matplotlib in Python?

六月ゝ 毕业季﹏ 提交于 2021-01-19 06:15:47
问题 How do I make the horizontal axis pass through the origin? import numpy as np import matplotlib.pyplot as plt rateList=[0,0.08,.1,.12,.15,.175,.225,.25,.275,.3,.325,.35] list1=[-316.8,-424,-2.8,622,658,400,83,16.8,0] NPV_Profile1=[np.npv(x,list1) for x in rateList] list2=[-496,-760,84,1050.4,658,400,83,16.8,0] NPV_Profile2=[np.npv(x,list2) for x in rateList] plt.plot(rateList,NPV_Profile1,rateList,NPV_Profile2) plt.show() 回答1: Try with: import numpy as np import matplotlib.pyplot as plt

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

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