matplotlib

Weird behavior of matplotlib plt.Rectangle

时间秒杀一切 提交于 2021-02-19 02:05:48
问题 I was trying to make a " matplotlib cake ". ;) I have the following code: It should print a blue and an red rectangle, divided by a green "coating". import matplotlib.pyplot as plt def save_fig(layer): # Hide the right and top spines ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) # Sacale axis plt.axis('scaled') fig.savefig(layer+'.pdf', dpi=fig.dpi) fig.savefig(layer+'.jpeg', dpi=fig.dpi) gap =10 fig, ax = plt.subplots() rectangle_gap = plt.Rectangle((0-gap, 0),

Weird behavior of matplotlib plt.Rectangle

心已入冬 提交于 2021-02-19 02:05:42
问题 I was trying to make a " matplotlib cake ". ;) I have the following code: It should print a blue and an red rectangle, divided by a green "coating". import matplotlib.pyplot as plt def save_fig(layer): # Hide the right and top spines ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) # Sacale axis plt.axis('scaled') fig.savefig(layer+'.pdf', dpi=fig.dpi) fig.savefig(layer+'.jpeg', dpi=fig.dpi) gap =10 fig, ax = plt.subplots() rectangle_gap = plt.Rectangle((0-gap, 0),

Matplotlib - set pad between arrow and text in annotate function

若如初见. 提交于 2021-02-19 01:34:34
问题 How do I set the distance (padding) between the arrow and the text in matplotlib's annotate function? Sometimes the text ends up being too close to the arrow and I would like to move them a little further apart. Basic example: import matplotlib.pyplot as plt plt.annotate('Here it is!',xy=(-1,-1),xytext=(0,0), arrowprops=dict(arrowstyle='->',lw=1.5)) plt.xlim(-10,10) plt.ylim(-10,10) plt.show() 回答1: For fancy arrows you can play with the bbox properties: fig, ax = plt.subplots(1, 3, figsize=(7

Matplotlib - set pad between arrow and text in annotate function

江枫思渺然 提交于 2021-02-19 01:33:55
问题 How do I set the distance (padding) between the arrow and the text in matplotlib's annotate function? Sometimes the text ends up being too close to the arrow and I would like to move them a little further apart. Basic example: import matplotlib.pyplot as plt plt.annotate('Here it is!',xy=(-1,-1),xytext=(0,0), arrowprops=dict(arrowstyle='->',lw=1.5)) plt.xlim(-10,10) plt.ylim(-10,10) plt.show() 回答1: For fancy arrows you can play with the bbox properties: fig, ax = plt.subplots(1, 3, figsize=(7

How do I stagger or offset x-axis labels in Matplotlib?

随声附和 提交于 2021-02-19 01:24:55
问题 I was wondering if there is an easy way to offset x-axis labels in a way similar to the attached image. 回答1: You can loop through your x axis ticks and increase the pad for every other tick so that they are lower than the other ticks. A minimal example would be: import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1,2,3,4,5]) ax.set_xticks([1,2,3,4,5]) ax.set_xticklabels(["A","B","C","D","E",]) # [1::2] means start from the second element in the list and get every other element

How can I make seaborn distribution subplots in a loop?

混江龙づ霸主 提交于 2021-02-19 01:16:49
问题 I have a 5D array called data for i in range(10): sns.distplot(data[i,0,0,0], hist=False) But I want to make them inside subplots instead. How can I do it? Tried this: plt.rc('figure', figsize=(4, 4)) fig=plt.figure() fig, ax = plt.subplots(ncols=4, nrows=3) for i in range(10): ax[i].sns.distplot(data[i,0,0,0], hist=False) plt.show() This obviously doesn't work. 回答1: You would want to use the ax argument of the seaborn distplot function to supply an existing axes to it. Looping can be

How can I make seaborn distribution subplots in a loop?

和自甴很熟 提交于 2021-02-19 01:14:26
问题 I have a 5D array called data for i in range(10): sns.distplot(data[i,0,0,0], hist=False) But I want to make them inside subplots instead. How can I do it? Tried this: plt.rc('figure', figsize=(4, 4)) fig=plt.figure() fig, ax = plt.subplots(ncols=4, nrows=3) for i in range(10): ax[i].sns.distplot(data[i,0,0,0], hist=False) plt.show() This obviously doesn't work. 回答1: You would want to use the ax argument of the seaborn distplot function to supply an existing axes to it. Looping can be

matplotlib: Stretch image to cover the whole figure

元气小坏坏 提交于 2021-02-18 22:53:58
问题 I am quite used to working with matlab and now trying to make the shift matplotlib and numpy. Is there a way in matplotlib that an image you are plotting occupies the whole figure window. import numpy as np import matplotlib.pyplot as plt # get image im as nparray # ........ plt.figure() plt.imshow(im) plt.set_cmap('hot') plt.savefig("frame.png") I want the image to maintain its aspect ratio and scale to the size of the figure ... so when I do savefig it exactly the same size as the input

Why is Jupyter Notebook creating duplicate plots when making updating plots

自作多情 提交于 2021-02-18 22:43:31
问题 I'm trying to make plots in a Jupyter Notebook that update every second or so. Right now, I just have a simple code which is working: %matplotlib inline import time import pylab as plt import numpy as np from IPython import display for i in range(10): plt.close() a = np.random.randint(100,size=100) b = np.random.randint(100,size=100) fig, ax = plt.subplots(2,1) ax[0].plot(a) ax[0].set_title('A') ax[1].plot(b) ax[1].set_title('B') display.clear_output(wait=True) display.display(plt.gcf()) time

3D Probability Density Plots in Python

試著忘記壹切 提交于 2021-02-18 19:32:34
问题 I am working on a data set consisting of 'pulse length' values and 5 or 6 'voltage values' corresponding to each of the pulse lengths. The first value is pulse length followed by voltages. Find the table below. 15 -56V -47V -53V -50V -50V 16 -49V -46V -52V -47V -50V 17 -50V -51V -47V -50V -49V 18 -50V -51V -48V -48V -45V 19 -49V -51V -45V -47V -52V 20 -45V -47V -50V -47V -54V 21 -46V -52V -52V -49V -54V 22 -53V -51V -53V -56V -52V 23 -52V -45V -51V -56V -53V 24 -51V -52V -54V -58V -52V 25