matplotlib

Python DataFrame - plot a bar chart for data frame with grouped-by columns (at least two columns)

自闭症网瘾萝莉.ら 提交于 2021-02-16 21:12:11
问题 I've been struggling to recreate this Excel graph in python using matlplotlib: The data is in a dataframe; I'm trying to automate the process of generating this graph. I've tried unstacking my dataframe, subplotting, but I haven't managed to create the "Zone" index which is so elegant in Excel. I have successfully managed to plot the graph without this "Zone" index, but that's not really what I want to do. Here is my code: data = pd.DataFrame( { 'Factory Zone': ["AMERICAS","APAC","APAC","APAC

Python DataFrame - plot a bar chart for data frame with grouped-by columns (at least two columns)

别等时光非礼了梦想. 提交于 2021-02-16 21:11:06
问题 I've been struggling to recreate this Excel graph in python using matlplotlib: The data is in a dataframe; I'm trying to automate the process of generating this graph. I've tried unstacking my dataframe, subplotting, but I haven't managed to create the "Zone" index which is so elegant in Excel. I have successfully managed to plot the graph without this "Zone" index, but that's not really what I want to do. Here is my code: data = pd.DataFrame( { 'Factory Zone': ["AMERICAS","APAC","APAC","APAC

Specifying colors for multiple lines on plot using matplotlib and pandas [duplicate]

时间秒杀一切 提交于 2021-02-16 20:48:27
问题 This question already has an answer here : Matplotlib: change the colors of the result of group by (1 answer) Closed 7 months ago . Pandas dataframe groupby plot I have a similar dataframe to the one in the above question, but it has around 8 ticker symbols. I've defined a list of colours called 'colors' that correspond with the tickers, but when I do: df.groupby('ticker')['adj_close'].plot(color=colors) all the lines on the plot for each of the tickers are the same colour (i.e. the first

Specifying colors for multiple lines on plot using matplotlib and pandas [duplicate]

六眼飞鱼酱① 提交于 2021-02-16 20:48:12
问题 This question already has an answer here : Matplotlib: change the colors of the result of group by (1 answer) Closed 7 months ago . Pandas dataframe groupby plot I have a similar dataframe to the one in the above question, but it has around 8 ticker symbols. I've defined a list of colours called 'colors' that correspond with the tickers, but when I do: df.groupby('ticker')['adj_close'].plot(color=colors) all the lines on the plot for each of the tickers are the same colour (i.e. the first

Matplotlib to plot a pairplot?

℡╲_俬逩灬. 提交于 2021-02-16 20:13:16
问题 Yesterday I posted this: Correlation scatter plot using DataFrame matrix? Because my English is not so good on the technical side, it was hard for me to explain what was my problem. I'm trying to be able to plot a pairplot using this correlation data: https://i.stack.imgur.com/uJvG1.png ozone,radiation,temperature,wind, 1.0,0.3483416929936026,0.6985414096486389,-0.6129507522144628 0.3483416929936026,1.0,0.2940876437245132,-0.12736562398818144 0.6985414096486389,0.2940876437245132,1.0,-0

Python学习笔记(matplotlib篇)--坐标轴刻度

落爺英雄遲暮 提交于 2021-02-16 17:02:25
Python学习笔记--坐标轴刻度   参靠视频:《 Python数据可视化分析 matplotlib教程》链接: https://www.bilibili.com/video/av6989413/?p=6 所用的库及环境 :   IDE:Pycharm   Python环境:python3.7   Matplotlib: Matplotlib 1.11   Numpy: Numpy1.15.   Datetime :Datetime 坐标轴刻度 概念 当需要把x,y坐标轴刻度调整的更密集些或者更宽松点 学习如何调整x,y坐标轴刻度 坐标轴刻度调整  面向对象形式 pyplort形式 locater_params 介绍 文档: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.locator_params.html#matplotlib.pyplot.locator_params 介绍:Control behavior of tick locators. 属性: axis: 介绍:此属性参数表示要操作的轴,默认是both, 如果想只改变x轴就把参数置位‘x’,y轴相同   可选参数:both,x,y   nbins: 介绍:表示要操作的坐标轴一共有多少格   可选参数:可以是数字,表示坐标轴一共有多少格,数字越大格越多,越密集

Matplotlib: Histogram from a list of frequencies

落花浮王杯 提交于 2021-02-16 15:43:25
问题 I have a list x = [90, 100, 121, 123, 88]. These values in the list are frequencies of occurrence of an event in 5 different trials. I am looking to create a histogram from this list. I simply tried: plt.hist(x) plt.show() I get this: I need something like this: Note: Very New to Python. And still learning when and how to use Stackoverflow. 回答1: Since the list x contains the frequencies then use a bar plot: x = [90, 100, 121, 123, 88] plt.bar(range(1,6), x) plt.ylabel('frequency') plt.show()

How can I draw an errorbar graph without lines and points in Matplotlib?

痞子三分冷 提交于 2021-02-16 15:27:12
问题 I am currently using the following code to plot errorbar graphs. plt.errorbar(log_I_mean_, log_V2_mean_, xerr, yerr, '.') However, the end result shows a circular point in the center of each errorbar intersection point. How can I plot just the errorbars without the central point, as is required in scientific work? 回答1: use 'none' instead of '.' : import matplotlib.pyplot as plt x = np.arange(0.1, 4, 0.5) y = np.exp(-x) yerr = 0.1 + 0.2*np.sqrt(x) xerr = 0.1 + yerr plt.figure() plt.errorbar(x,

Python: Plt bar plot - different colors

淺唱寂寞╮ 提交于 2021-02-16 15:19:06
问题 In Python, how can I make the 'reported' bars green, and 'UNREPORTED' bars red? I want to give different color to each of the reported and UNREPORTED bars in my graph. new = (('AXIN', 37, 'reported'), ('LGR', 30, 'UNREPORTED'), ('NKD', 24, 'reported'), ('TNFRSF', 23, 'reported'), ('CCND', 19, 'reported'), ('APCDD', 18, 'reported'), ('TRD', 16, 'reported'), ('TOX', 15, 'UNREPORTED'), ('LEF', 15, 'reported'), ('MME', 13, 'reported')) #sort them as most common gene comes first new = sorted(new,

colorbar changes the size of subplot in python

非 Y 不嫁゛ 提交于 2021-02-16 13:57:47
问题 I use the following code to generate side-by-size images and I need to add colorbar only to the second image in the row. I use the following code for it import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable import matplotlib.gridspec as gridspec def plotting(x): gs1 = gridspec.GridSpec(1, 2) gs1.update(wspace=0.005, hspace=0.005) plt.subplot(gs1[0]) plt.imshow(x) plt.axis('off') plt.title('dog') ax1 = plt.subplot(gs1[1]) imc = plt.imshow(x, cmap='hot',