matplotlib

Not able to create a 3x3 grid of subplots to visualize 9 Series individually

本小妞迷上赌 提交于 2021-01-29 16:25:27
问题 I want to have a 3x3 grid of subplots to visualize each Series individually. I first created some toy data: import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt sns.set(style='whitegrid', rc={"figure.figsize":(14,6)}) rs = np.random.RandomState(444) dates = pd.date_range(start="2009-01-01", end='2019-12-31', freq='1D') values = rs.randn(4017,12).cumsum(axis=0) data = pd.DataFrame(values, dates, columns =['a','b','c','d','e','f','h','i','j','k','l','m'])

How to plot the Monte Carlo pi histogram?

旧城冷巷雨未停 提交于 2021-01-29 16:12:47
问题 I am trying to plot a histogram distribution of pi from the Monte Carlo method but I am getting histograms that are either skewed to the left or right each time I run the simulation instead of a histogram that is approximately symmetric and peaks at around 3.14. The output histograms also have some gaps and I think I am approximating pi correctly. My code is below: [...(importing relevant modules)] N = 1000 #total number of random points circlex = [] circley = [] squarex = [] squarey = [] pis

Nesting or combining matplotlib figures and plots?

天大地大妈咪最大 提交于 2021-01-29 16:11:29
问题 I have a function that takes an arbitrary length 3D data set of dates, prices(float), and some resulting value(float) and makes a set of seaborn heatmaps split by year. The pseudocode is as follows (note the number of years varies by dataset so I need it to arbitrarily scale): def makePlots(data): split data by year fig,axs=plt.subplots(1, numYears) x=0 for year in years sns.heatmap(data[year], ax = axs[x++]) return axs this outputs a single matplotlib figure with a heatmap for each year next

Add a Matplotlib Graph to a Widget in KivyMD

风流意气都作罢 提交于 2021-01-29 15:45:09
问题 I am currently creating a mobile app with KivyMD which serves for managing travel expense requests. The user will enter a desired requested amount for different types of expenses on an MDTextField. I want to add a donut graph made with patplotlib into an MDBoxLayout. Such graph should automatically update as the request is filled. (For clarity I will include a screenshot. The square in red is the desired location for my graph). I created a method called update_method_graph and used fixed

Matplotlib add gridlines not working as expected

二次信任 提交于 2021-01-29 15:41:53
问题 Using matplotlib subplots() in Jupyter Notebook, and using "seaborn-whitegrid" plot.style() . I am trying to add minor gridlines to my x-axis, which is in log. What am I missing? import matplotlib.pyplot as plt %matplotlib inline plt.style.use('seaborn-whitegrid') x, y = [(1, 9, 65, 142, 330), (0, 0.16, 0.50, 0.84, 1)] fig, axes = plt.subplots(3,5, figsize=(8.5,5.5), constrained_layout=True) #counter = 0 for ax in axes.flat: ax.plot(x,y) ax.set_title('Dataset-A', fontsize=8) ax.set_xlabel('x'

Absolute Values and Percentage Values Side by Side in Bar Chart Matplotlib

女生的网名这么多〃 提交于 2021-01-29 15:16:01
问题 I would like to count on your help for the following problem that I have been facing. I've been trying, but without success, to put absolute values and percentage values side by side. Where 53 and 47 are percentage values and would be outside the parentheses and 17 and 15 are absolute values and would be inside the parentheses. Both absolute values and percentage values are already known, therefore, there is no need for any calculation to obtain them. I leave my code here for you to see how

Seaborn: Arrange multiple Facetgrids

谁都会走 提交于 2021-01-29 14:51:02
问题 I have some trouble understanding seaborns FacetGrids. I have 16 cotegorical columns in my data and I want to use countplot to show the distribution over the values. In addition i have one target variable Y which have to classes. Now I want the calculations for the countplot to be class-dependet. So for each of my 16 input variables I want to have to subplots ( for class 0 and class 1). I can achieve this by (not sure if this is the best solution): for col in df: g = sbn.FacetGrid(df, col="Y"

Matplotlib's rstride, cstride messes up color maps in plot_surface 3D plot?

放肆的年华 提交于 2021-01-29 14:37:51
问题 I have a large dataset consisting of 3595 .csv files containing 1252 pairs of x,y tuples. Each file represents a time frame. These are plottet using plot_surf() . I found out, that my data will be sieved (in regards to the files, or time frames) by default with a step of 10 when plotting my data, which is why I need to specify rstride=1, cstride=1 in my artist in order to plot everything. When I did this, I accidentally discovered the solution to a problem I faced earlier: By default the plot

Pcolormesh or column_stack function has memory error when I try creating images in a loop even after closing figures

人走茶凉 提交于 2021-01-29 14:30:58
问题 I am quite new to python and am trying to plot data using pcolormesh, and have to create many images in a loop with quite large arrays. The code to generate the data works fine and creates the arrays, however the problem arises when I try to plot. It seems that the first iteration creates the image fine, however the second has a memory error unlike the usual ones I've seen before. This one comes from the column_stack function apparently multiplying my x and y arrays together. I'm not entirely

How to plot a gradient color line?

巧了我就是萌 提交于 2021-01-29 14:27:50
问题 This code plots a scatterplot with gradient colors: import matplotlib.pyplot as plt import numpy as np x = np.arange(30) y = x t = x plt.scatter(x, y, c=t) plt.colorbar() plt.show() but how would I plot a gradient color line with a x and y coordinate? 回答1: Did you already have a look at https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/multicolored_line.html? EDIT: as suggested in the comments, a minimal working example could be import numpy as np import matplotlib.pyplot as plt