matplotlib

Autoscale a matplotlib Axes to make room for legend

扶醉桌前 提交于 2021-01-28 06:53:45
问题 I am plotting a 2D view of a spacecraft orbit using matplotlib. On this orbit, I identify and mark certain events, and then list these events and the corresponding dates in a legend. Before saving the figure to a file, I autozoom on my orbit plot, which causes the legend to be printed directly on top of my plot. What I would like to do is, after autoscaling, somehow find out the width of my legend, and then expand my xaxis to "make room" for the legend on the right side of the plot.

How to plot a function oriented on a local x axis matplotlib 3d?

青春壹個敷衍的年華 提交于 2021-01-28 06:51:17
问题 I need to plot a f(z) function on 3D matplotlib, but on a local x axis, defined by two dots and fill in between them, to stay as shown in the image: I have these two points that define the local axis x, 20 values ​​between them and the corresponding 20 values ​​of f(z), but I can not figure out how to plot. Can someone help me? valuesx = np.arange(0.0, 5, 5/20) # local axis values ​​x self.listax.append(valuesx) for l in valuesx: fy= 2*x**2-4 #equation fyx = eval(fy, {'x': l}) self.listay

Plotting a barplot with a vertical line in pyplot-seaborn-pandas

烈酒焚心 提交于 2021-01-28 06:45:09
问题 I am having trouble doing something that seems to me straightforward. My data is: ROE_SP500_Q2_2018_quantile.to_json() '{"index":{"0":0.0,"1":0.05,"2":0.1,"3":0.15,"4":0.2,"5":0.25,"6":0.3,"7":0.35,"8":0.4,"9":0.45,"10":0.5,"11":0.55,"12":0.6,"13":0.65,"14":0.7,"15":0.75,"16":0.8,"17":0.85,"18":0.9,"19":0.95},"ROE_Quantiles":{"0":-0.8931,"1":-0.0393,"2":0.00569,"3":0.03956,"4":0.05826,"5":0.075825,"6":0.09077,"7":0.10551,"8":0.12044,"9":0.14033,"10":0.15355,"11":0.17335,"12":0.1878,"13":0

Python Error only length-1 arrays can be converted to Python scalars

≡放荡痞女 提交于 2021-01-28 06:30:19
问题 I am new to python coding and i am writing a code to calculate the sum of a series, i started by writing a function where the input is the number of iterations of the sum, but when i compile it gives me the error in the line under def G(i) : only length-1 arrays can be converted to Python scalars Can you help me please import matplotlib.pyplot as plt import numpy as np import scipy.special as sp import pylab as pylab def G(i): return (sum(((-1*(2*l+1))/(4*np.pi*(l**2+l)))*sp.legendre(l)(0.5)

Continue code after closing matplotlib figure

纵饮孤独 提交于 2021-01-28 06:18:49
问题 I am writing a routine where I can append a set of datafiles. The first part of the code imports a single datafile and displays it using matplotlib. I can then use a slider to define a specific x range (i.e. to exclude noisy or irrelevant parts). The second part of the code involves an edit routine where I edit the range of all the datafiles in the specific folder based on this newly set x range (i.e. removing all of the rows). The first part of the code is not a problem for me and results in

matplotlib.pyplot.axes() arguments confusion

一曲冷凌霜 提交于 2021-01-28 06:07:17
问题 The objective is to insert a sub_figure in a simple plot as follows: import numpy as np from matplotlib import pyplot as plt X = np.linspace(-6, 6, 1024) Y = np.sinc(X) X_detail = np.linspace(-3, 3, 1024) Y_detail = np.sinc(X_detail) plt.plot(X, Y, c = 'k') sub_axes = plt.axes([0.6,0.6,0.25,0.25]) sub_axes.plot(X_detail, Y_detail, c = 'k') plt.setp(sub_axes) plt.show() The code above gives the following output: The matplotlib documentation says the argument the matplotlib.pyplot.axes()

ImportError: No module named 'matplotlib._path' when running a python script in apache2

爱⌒轻易说出口 提交于 2021-01-28 05:45:39
问题 I have been busting my head over this for a few hours now but I cant nail down the reason why this error occurs. I am trying to run a simple python script in my apache2 server- #!/usr/bin/python3.5 import cgi import cgitb cgitb.enable() import sys sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages") sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages") # HEADERS print("Content-Type:text/html; charset=UTF-8") print() # blank line required at end of headers # CONTENT

Can you copy only some subplots to a new figure?

耗尽温柔 提交于 2021-01-28 05:32:53
问题 Is there a way to copy an axis (subplot) to a new figure? This is straightforward in other languages, but I understand that not even a deep copy would work with python's matplotlib. E.g. if I have a figure with 6 subplots, how can I copy 2 of those subplots to a new figure, with all the settings? Labels, tickmarks, legend, grid, etc. I have found this answer , which is actually 2 in 1: the first no longer works (deprecated syntax), while I couldn't get the second to work in my case. I manage

cartopy: how to add an image on top of map

烂漫一生 提交于 2021-01-28 05:22:53
问题 How to overlay a custom image on top of a cartopy map? If I do ax = plt.axes(projection=map_quest_aerial.crs) ax.set_extent([lon_0, lon_1, lat_0, lat_1]) plt.imshow('myimage.png', extent=(x0,x1,y0,y1)) plt.show() my image shows up correctly in the axes. But, if I try to add the background map image, my image no longer appears: ax = plt.axes(projection=map_quest_aerial.crs) ax.set_extent([lon_0, lon_1, lat_0, lat_1]) ax.add_image(map_quest_aerial, 10) plt.imshow('myimage.png', extent=(x0,x1,y0

Low FPS in MatPlotlib

南笙酒味 提交于 2021-01-28 05:22:46
问题 Faced with the fact that MatPlotlib when using self.frame.canvas.draw() I got only 12 FPS on a simple chart. I found a good article about acceleration speed MatPlotlib: https://bastibe.de/2013-05-30-speeding-up-matplotlib.html But part of the examples is working code, but the example with the fastest code (500 FPS) is not working . Attempts to read the documentation MatPlotlib have not yet led to success in understanding where the error is in the code: «AttributeError: draw_artist can only be