我想绘制属于某些组的变量.
假设我有6个变量,我想要分成这3组,并绘制像维恩图.我想将变量名称注释为三个气泡.
在这个简单的例子中,我们可以说1个变量在组1中,3个变量在组2中,2个变量在组3中.
任何人都可以帮我一个简单的例子来说明如何在matplotlib中做到这一点?
我无法optimize_for_inference
在一个简单的,保存的TensorFlow图(Python 2.7;安装包pip install tensorflow-gpu==1.0.1
)上成功运行该模块.
这是我的Python脚本,用于生成并保存一个简单的图形,以便为我的输入x
placeholder
操作添加5 .
import tensorflow as tf
# make and save a simple graph
G = tf.Graph()
with G.as_default():
x = tf.placeholder(dtype=tf.float32, shape=(), name="x")
a = tf.Variable(5.0, name="a")
y = tf.add(a, x, name="y")
saver = tf.train.Saver()
with tf.Session(graph=G) as sess:
sess.run(tf.global_variables_initializer())
out = sess.run(fetches=[y], feed_dict={x: 1.0})
print(out)
saver.save(sess=sess, save_path="test_model")
Run Code Online (Sandbox Code Playgroud)
我有一个简单的恢复脚本,可以重新创建已保存的图形并恢复图形参数.保存/恢复脚本都生成相同的输出.
import tensorflow as tf
# Restore simple graph and test model output
G = tf.Graph()
with tf.Session(graph=G) …
Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何运行Python的line_profiler来逐行执行这个问题的答案中给出的格式.
我安装了模块并调用它的LineProfiler
对象如下所示,但我得到的输出只是一次,而不是逐行汇总.
有任何想法吗?此外,我如何获得numbers = [random.randint(1,100) for i in range(1000)]
任何功能之外的线路的时间?
from line_profiler import LineProfiler
import random
def do_stuff(numbers):
s = sum(numbers)
l = [numbers[i]/43 for i in range(len(numbers))]
m = ['hello'+str(numbers[i]) for i in range(len(numbers))]
numbers = [random.randint(1,100) for i in range(1000)]
profile = LineProfiler(do_stuff(numbers))
profile.print_stats()
[] Timer unit: 3.20721e-07 s
Run Code Online (Sandbox Code Playgroud) 我想在我/myhome
没有root权限的帐户的服务器上使用matplotlib .
我下载了matplotlib源代码并尝试使用distutils和用户sheme安装它python setup.py install --user
,但是它返回了以下消息:
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.3.1]
python: yes [2.7.3 (default, Jan 2 2013, 13:56:14) [GCC
4.7.2]]
platform: yes [linux2]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.6.2]
dateutil: yes [using dateutil version 1.5]
tornado: yes [tornado was not found. It is required for the
WebAgg backend. pip/easy_install may attempt to
install it after matplotlib.]
pyparsing: yes [pyparsing was not found. It is required …
Run Code Online (Sandbox Code Playgroud) 我使用的是Mac OSX 10.8,之前我使用过macports,但是我改用了brew.
Snows-MacBook-Pro:~ Mac$ brew search matplotlib
samueljohn/python/matplotlib
Snows-MacBook-Pro:~ Mac$ pip search matplotlib
matplotlib - Python plotting package
Run Code Online (Sandbox Code Playgroud)
所以我的问题很简单.我应该使用brew或pip来安装matplotlib吗?有什么区别和什么?
我的目标是让大熊猫,ipythone笔记本和simpleCV启动并运行.
我使用easy_install for matplotlib-venn时遇到问题.我在使用python2.7的Windows计算机上.我怀疑路径不正确,但我不知道如何解决这个问题.谁能帮助我?我正在尝试在CMD提示符中运行easy_install命令附加输出.
C:\Python27\Scripts>easy_install matplotlib-venn
Searching for matplotlib-venn
Reading https://pypi.python.org/simple/matplotlib-venn/
Download error on https://pypi.python.org/simple/matplotlib-venn/: [Errno 11004]
getaddrinfo failed -- Some packages may not be found!
Couldn't find index page for 'matplotlib-venn' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 11004] getaddrinfo fai
led -- Some packages may not be found!
No local packages or download links found for matplotlib-venn
error: Could not find suitable distribution for Requirement.parse('matplotlib-ve
nn')
install …
Run Code Online (Sandbox Code Playgroud) 我的python脚本中出现此错误:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from utils import progress_bar_downloader
import os
#Hosting files on my dropbox since downloading from google code is painful
#Original project hosting is here: https://code.google.com/p/hmm-speech-recognition/downloads/list
#Audio is included in the zip file
link = 'https://dl.dropboxusercontent.com/u/15378192/audio.tar.gz'
dlname = 'audio.tar.gz'
if not os.path.exists('./%s' % dlname):
progress_bar_downloader(link, dlname)
os.system('tar xzf %s' % dlname)
else:
print('%s already downloaded!' % dlname)
Run Code Online (Sandbox Code Playgroud)
我想使用matplotlib,但它给出了语法错误,我试过sudo apt-get install python-matplotlib
比较以下代码:
test = pd.DataFrame({'date':['20170527','20170526','20170525'],'ratio1':[1,0.98,0.97]})
test['date'] = pd.to_datetime(test['date'])
test = test.set_index('date')
ax = test.plot()
Run Code Online (Sandbox Code Playgroud)
我最后补充说DateFormatter
:
test = pd.DataFrame({'date':['20170527','20170526','20170525'],'ratio1':[1,0.98,0.97]})
test['date'] = pd.to_datetime(test['date'])
test = test.set_index('date')
ax = test.plot()
ax.xaxis.set_minor_formatter(dates.DateFormatter('%d\n\n%a')) ## Added this line
Run Code Online (Sandbox Code Playgroud)
与第二张图的问题是,它开始于5-24
代替5-25
.此外,5-25
2017年是星期四而不是星期一.是什么导致了这个问题?这个时区有关系吗?(我不明白为什么日期数字叠加在一起)
我是数据科学和分析的新手。在 Kaggle 上研究了很多内核之后,我制作了一个预测房产价格的模型。我已经使用我的训练数据测试了这个模型,但现在我想在我的测试数据上运行它。我有一个 test.csv 文件,我想使用它。我怎么做?我之前对训练数据集做了什么:
#loading my train dataset into python
train = pd.read_csv('/Users/sohaib/Downloads/test.csv')
#factors that will predict the price
train_pr = ['OverallQual','GrLivArea','GarageCars','TotalBsmtSF','FullBath','YearBuilt']
#set my model to DecisionTree
model = DecisionTreeRegressor()
#set prediction data to factors that will predict, and set target to SalePrice
prdata = train[train_pr]
target = train.SalePrice
#fitting model with prediction data and telling it my target
model.fit(prdata, target)
model.predict(prdata.head())
Run Code Online (Sandbox Code Playgroud)
现在我尝试做的是,复制整个代码,并将“train”更改为“test”,将“predate”更改为“testprdata”,我认为它会起作用,但遗憾的是没有。我知道我做错了什么,我不知道那是什么。
我正在尝试将matplotlib对象加载到reportlab中.这是我的代码:
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
from reportlab.platypus import Paragraph, SimpleDocTemplate, Spacer, Image
from matplotlib import pyplot as plt
def __get_img_data():
"""
returns the binary image data of the plot
"""
img_file = NamedTemporaryFile(delete=False)
plt.savefig(img_file.name)
img_data = open(img_file.name + '.png', 'rb').read()
os.remove(img_file.name)
os.remove(img_file.name + '.png')
return img_data
def get_plot():
# HERE I PLOT SOME STUFF
img_data = __get_img_data()
plt.close()
return img_data
class NumberedCanvas(canvas.Canvas):
def __init__(self):
pass
class ReportTemplate:
def __init__(self):
pass
def _header_footer(self, canvas, doc):
pass
def …
Run Code Online (Sandbox Code Playgroud) python ×11
matplotlib ×7
python-2.7 ×2
data-science ×1
datetime ×1
dependencies ×1
easy-install ×1
homebrew ×1
installation ×1
macos ×1
module ×1
pandas ×1
php ×1
profiling ×1
reportlab ×1
scikit-learn ×1
tensorflow ×1
venn-diagram ×1