matplotlib绘图进阶
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
matplotlib绘图进阶
/pipisorry/article/details/37766161远程绘图,在matplotlib中的一个坐标轴上画一条直线光标,绘制LaTeX数学公式,对数坐标轴。
远程绘图python使用ssh进行远程解释器绘图时出错:RuntimeError: Invalid DISPLAY variable主要原因:By default, matplotlib will use something like the TkAgg backend. This requires an X-server to be running.解决1:import matplotlib
e('Agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt123但是这个并不能使代码在远程执行,而在本地绘图,只能将绘图保存为图片文件再下载下来看。[How to save a figure remotely with pylab? [duplicate]]解决2:
[How do you plot a graph when developing on a remote machine through ssh only][Matplotlib: display plot on a remote machine]
解决3:代码在远程执行,而在本地绘图There are a few possibilities If your remote machine is somehow unixish, you may use the X Windows (then your session is on the
remote machine and display on the local
machine)mpld3bokeh and iPython notebooknbagg backend of matplotlib.¨Alternative #1 requires you to have an X server on your machine and a connection between the two machines (possibly tunneled through ssh, etc.) So, this is OS dependent, and the performance depends on the connection between the two machines. Alternatives #2 and #3 are very new but promising. They have quite different approaches, mpl3d enables the use of standard matplotlib plotting commands, but with large datasets bokeh may be more useful. Alternative #4 is probably the ultimate solution (see tcaswell's comments), but not yet available without using a development version of matplotlib (i.e. there may be some installation challenges). On the other hand, if you can hold your breath for a week, 1.4.0 will be out. The upcoming release (1.4.0, should be out by end of August 2014, release candidates are available) will ship with the nbagg backend which provides interactive figures with out needing to go to native clients or resorting to using d3. All you need to do in your note book is: import matplotlib
e('nbagg')
from matplotlib import pyplot as plt And then to plot
plt.plot(range(3))
plt.show()[how to display matplotlib plots on local machine?]1) on remote host (VPS, Ubuntu 16.04) I had to install X11 server, which I did by: sudo apt-get install xorg sudo apt-get install openbox122) On remote host I had to make sure that X11Forwarding is enabled in
/etc/ssh/sshd_config3) On local Win10 machine I had to install Xming server and launch it with default settings.4) On local Win10 machine I had to configure Putty to use
X11 forwarding (Connection-> SSH -> X11 Forwarding) with default settings and keep connection open while running PyCharm (it seems there is no option in PyCharm to enable x11 forwarding, so putty must be running in the background)5) On remote machine I had to check Display number (echo $DISPLAY) - this can be different for everyone. For me it was localhost:10.06) In PyCharm Run configuration -> Environment variables I had to add DISPLAY=localhost:10.0After all these steps and Putty+Xming running in backgroud, I was able to execute remote code and bring graphic back to my Windows 10 PC![Python plotting on remote server using