matplotlib

LineCollection animation

放肆的年华 提交于 2021-01-29 09:56:15
问题 For the following code (MWE), if the line ax.set_axis_off() is commented out, then the animation shows nothing. Otherwise, the animation works as expected. My question is: why? from itertools import tee import numpy as np import matplotlib matplotlib.use('Agg') # noqa from matplotlib.animation import FuncAnimation, FFMpegWriter from matplotlib.collections import LineCollection from matplotlib.colors import ListedColormap, BoundaryNorm import matplotlib.pyplot as plt def pairwise(iterable): "s

How to set curvilinear lat lon gridline labels parallel to gridlines with cartopy?

空扰寡人 提交于 2021-01-29 09:40:55
问题 Description Is there a method available (or under consideration) to orient the lat lon gridline labels parallel to the gridlines as they intersect the plot boundary? Something like the labels seen in this plot. There seems to be an automated logic in place for orienting gridline labels as follows: Cartopy version 0.18.0b1 Code import matplotlib.pyplot as plt import cartopy.crs as ccrs rotated_crs = ccrs.RotatedPole(pole_longitude=120.0, pole_latitude=70.0) ax = plt.axes(projection=rotated_crs

Python: Axis disappearing in figure when animating with celluloid

廉价感情. 提交于 2021-01-29 08:57:39
问题 I am using celluloid (https://github.com/jwkvam/celluloid) to plot a function over several years and i love it so far, it works great! I have one small problem though, the edges of my plot disappear after the first loop. I have attached images of how this looks. First loop: Second loop: As you can see the axis has disappeared. I am using cartopy and matplotlib in jupyter notebook and this is my code for the animation: # Use 'Agg' so script only displays animation in HTML import matplotlib

Making python's matplotlib graphics look like graphics created using OriginPro

China☆狼群 提交于 2021-01-29 08:45:33
问题 I may have created a duplicate, but could not find exactly what I was looking for in any thread. I created graphics using OriginPro 8.5G and can not quite re-create them using matplotlib. I am quite new to styling graphics using mpl, but I will attach, what I have already tried and show some pictures. Plot created using OriginPro 8.5G Plot created using matplotlib.pyplot The code used is as follows: import matplotlib as mpl from matplotlib import rcParams, cycler import matplotlib.pyplot as

Multiple Y-axis with matplotlib with Twinx

梦想与她 提交于 2021-01-29 08:40:34
问题 Question: How to apply twinx with Pandas & matplotlib I know that this question has been answered by people multiple times but I just cant get my head around it. Any help will be greatly appreciated! Basically, I have this code. But I need the x axis to show the years and the secondary y axis to show the demand of the different car brands. import pandas as pd import csv df3=pd.read_csv('comparison.csv' df3.plot() plt.legend (loc='best', fontsize=15) plt.title('Comparison of Demand of Car

Add axes to a figure with a fixed size

吃可爱长大的小学妹 提交于 2021-01-29 08:29:20
问题 I would like to create a figure where subplots are added dynamically within a for-loop. It should be possible to define the width and height of each subplot in centimeters, that is, the more subplots are added, the bigger the figure needs to be to make room for 'incoming' subplots. In my case, subplots should be added row-wise so that the figure has to get bigger in the y-dimension . I came across this stackoverflow post, which might lead in the right direction? Maybe also the gridspec module

How do I make my plot show simple input as loaded from a(nother) class file?

点点圈 提交于 2021-01-29 08:27:50
问题 Got this: import pandas as pd from df import df import matplotlib as plt import seaborn as sns class Data_load: def __init__(self, df): self.df = pd.read_csv(df, delimiter=';') # Data information section def get_EDA_columns(self): return self.df.columns def get_EDA_info(self): return self.df.info() def get_EDA_describe(self): return self.df.describe() def get_EDA_shape(self): return self.df.shape def get_EDA_value_counts(self): return self.df.value_counts() def get_EDA_isnull(self): return

Adding a figure created in a function to another figure's subplot

做~自己de王妃 提交于 2021-01-29 08:27:29
问题 I created two functions that make two specific plots and returns me the respective figures: import matplotlib.pyplot as plt x = range(1,100) y = range(1,100) def my_plot_1(x,y): fig = plt.plot(x,y) return fig def my_plot_2(x,y): fig = plt.plot(x,y) return fig Now, outside of my functions, I want to create a figure with two subplots and add my function figures to it. Something like this: my_fig_1 = my_plot_1(x,y) my_fig_2 = my_plot_2(x,y) fig, fig_axes = plt.subplots(ncols=2, nrows=1) fig_axes

adding hatches to seaborn heatmap plot

心不动则不痛 提交于 2021-01-29 08:21:22
问题 Is there a way to hatch particular 'cells' in a seaborn heatmap, which e.g. fullfill a condition? I already tried it with masked arrays and matplotlib pcolor, but it turned out that it hatched the wrong cells. import numpy as np import seaborn as sns import matplotlib.pyplot as plt flights = sns.load_dataset("flights") flights = flights.pivot("month", "year", "passengers") zm = np.ma.masked_less(flights.values, 200) x= np.arange(0,12) y= np.arange(0,12) sns.heatmap(flights,linewidth=.1) plt

How to offset the x axis and log the y axis and to find the gradient of my graph from an external file

扶醉桌前 提交于 2021-01-29 08:16:02
问题 I am new to Python code and I need to graph my experiment data for my lab portfolio however I can't seem to log the y-axis and offset the x-axis or even know where to start for the gradient. I have tried np.log in various different ways and each time I get an error, for the offset (which 26408) I tried just subtracting that number from x, I have tried creating an array and subtracting that and again I end up with various errors. import matplotlib.pyplot as plt %matplotlib inline f = open(