matplotlib

Prevent grid lines from twin axis to be drawn on top of artists from original axis

可紊 提交于 2021-02-08 06:54:45
问题 I have an axis on which I plot some data and I have another twin axis which I use to draw grid lines at specific tick positions (other than the ticks of the original axis): import matplotlib.pyplot as plt import numpy as np f, ax = plt.subplots() ax.set_xlim([0, 1]) ax2 = ax.twiny() ax2.set_xlim([0, 1]) ax2.set_xticks(np.linspace(0, 1, 11)) ax2.xaxis.grid() x = np.linspace(0, 1, 100) ax.plot(x, np.sin(x), label='sin(x)') ax.legend() plt.show() Now this has the undesirable effect that the grid

Showing different size circles in heatmap with legend using Matplotlib

我的梦境 提交于 2021-02-08 06:39:39
问题 I am asking a question stemming from this original post Heatmap with circles indicating size of population I am trying to replicate this using my dataframe, however, my circles are non aligning to the plot. Secondary, I want to also create a legend which indicates the value relative to the size of circle. x= {'ID': {0: 'GO:0002474', 1: 'GO:0052548', 2: 'GO:0002483', 3: 'GO:0043062', 4: 'GO:0060333'}, 'TERM': {0: 'antigen processing and presentation of peptide antigen via MHC class I', 1:

Fill between arc patches - Matplotlib

雨燕双飞 提交于 2021-02-08 06:37:33
问题 I have an ellipse that I want to solid fill with colors in different sections. To achieve this I'm using arcs patches. I'm currently drawing multiple arcs and using zorder to overlap the appropriate arcs . Main issues are that I cannot solid fill arc patches and they are not neatly filling the ellipse . It would be great if the areas didn't overlap either so I could use transparency parameters. import matplotlib.pyplot as plt import matplotlib as mpl import math fig, ax = plt.subplots(figsize

how to add error bars to histogram diagram in python

这一生的挚爱 提交于 2021-02-08 05:33:42
问题 Hi I want to add error bars to the histogram within this code.I have seen few post about it but I didn't find them helpful.this code produce random numbers with Gaussian distribution and a kernel estimation apply to it.I need to have errorbars to estimate how much the histogram is inaccurate with changing the bandwidth from random import * import numpy as np from matplotlib.pyplot import* from matplotlib import* import scipy.stats as stats def hist_with_kde(data, bandwidth = 0.3): #set number

matplotlib multiple overlapping xlabels in 2 levels

五迷三道 提交于 2021-02-08 05:32:41
问题 I'm trying to find a solution to a situation where I have multiple xlabels in the plot, which I cannot give up any. The problem is that the xlabels are running on each other, making the plot not readable (as in subplot (1,1) ) I was wondering if I can somehow make each second label in another hight (as in the example attached) What I had in mind: 回答1: Two approaches Add a positive rotation to the ticks/labels: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.xticks.html Add two new

Annotate lines of a plot with matplotlib when hover with mouse [duplicate]

核能气质少年 提交于 2021-02-08 05:29:54
问题 This question already has answers here : Possible to make labels appear when hovering over a point in matplotlib? (10 answers) Closed 1 year ago . I want to annotate different lines on a plot when hovering with the mouse, the same way is done here with points Possible to make labels appear when hovering over a point in matplotlib? I tried to adapt this code as the following : import matplotlib.pyplot as plt import numpy as np; np.random.seed(1) y = np.random.rand(4,15) x = [np.arange(15) for

Cartopy: Can't plot vector field with uncertainties (and related questions)

喜你入骨 提交于 2021-02-08 05:24:13
问题 I've been trying for a while now to plot vector field with uncertainty ellipses in Cartopy. The idea is that if I have a location (lat/lon) and a vector (wind speed, for example), but that vector has an uncertainty (measured in standard deviation, for example), then I'd like to plot an ellipses around the tip of the arrow indicating that uncertainty. In GMT, psvelo does the trick, my goal is something like this. This is the same question as has been asked before here - I'm reopening it

Cartopy: Can't plot vector field with uncertainties (and related questions)

做~自己de王妃 提交于 2021-02-08 05:24:09
问题 I've been trying for a while now to plot vector field with uncertainty ellipses in Cartopy. The idea is that if I have a location (lat/lon) and a vector (wind speed, for example), but that vector has an uncertainty (measured in standard deviation, for example), then I'd like to plot an ellipses around the tip of the arrow indicating that uncertainty. In GMT, psvelo does the trick, my goal is something like this. This is the same question as has been asked before here - I'm reopening it

retrieve leave colors from scipy dendrogram

南楼画角 提交于 2021-02-08 05:17:35
问题 I can not get the color leaves from the scipy dendrogram dictionary. As stated in the documentation and in this github issue, the color_list key in the dendrogram dictionary refers to the links, not the leaves. It would be nice to have another key referring to the leaves, sometimes you need this for coloring other types of graphics, such as this scatter plot in the example below. import numpy as np import matplotlib.pyplot as plt from scipy.cluster.hierarchy import linkage, dendrogram # DATA

How to add a wedge sector onto a polar Matplotlib plot

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 04:41:13
问题 I wish to add a wedge outlining a group of polar data using Python's Matplotlib. I have tried using the Wedge patch artist unsuccessfully, due to unknown reasons. I wish to either understand these unknowns, or find an alternative to the patch artist approach. The primary issue is that the Wedge patch is not displaying as I am expecting it to. Given my code, I am expecting it to be oriented at an angle, and span a range of ~0.05 in radius. This places it within the sector plot here: 1 But this