我希望降低不同子图上刻度标签的密度
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from StringIO import StringIO
data = """\
a b c d
z 54.65 6.27 19.53 4.54
w -1.27 4.41 11.74 3.06
d 5.51 3.39 22.98 2.29
t 76284.53 -0.20 28394.93 0.28
"""
df = pd.read_csv(StringIO(data), sep='\s+')
gs = gridspec.GridSpec(3, 1,height_ratios=[1,1,4] )
ax0 = plt.subplot(gs[0])
ax1 = plt.subplot(gs[1])
ax2 = plt.subplot(gs[2])
df.plot(kind='bar', ax=ax0,color=('Blue','DeepSkyBlue','Red','DarkOrange'))
df.plot(kind='bar', ax=ax1,color=('Blue','DeepSkyBlue','Red','DarkOrange'))
df.plot(kind='bar', ax=ax2,color=('Blue','DeepSkyBlue','Red','DarkOrange'),rot=45)
ax0.set_ylim(69998, 78000)
ax1.set_ylim(19998, 29998)
ax2.set_ylim(-2, 28)
ax0.legend().set_visible(False)
ax1.legend().set_visible(False)
ax2.legend().set_visible(False)
ax0.spines['bottom'].set_visible(False)
ax1.spines['bottom'].set_visible(False) …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制/绘制(matplotlib或其他python库)一个大距离矩阵的2D网络,其中距离将是草绘网络的边缘以及其节点的线和列.
DistMatrix =
[ 'a', 'b', 'c', 'd'],
['a', 0, 0.3, 0.4, 0.7],
['b', 0.3, 0, 0.9, 0.2],
['c', 0.4, 0.9, 0, 0.1],
['d', 0.7, 0.2, 0.1, 0] ]
Run Code Online (Sandbox Code Playgroud)
我正在寻找从这样的(更大的:数千列和线)距离矩阵绘制/绘制2d网络:节点'a'通过边缘深度0.3,节点'c'和'd链接到节点'b' '将被边缘深度0.1绑定.我可以使用哪些工具/库(距离矩阵可以转换成numpy矩阵)来获得这种网络的草图/图形投影?(pandas,matplotlib,igraph,......?)和一些导致快速做到这一点(我不会定义我的自我Tkinter功能来做那个;-))?谢谢你的回答.
我必须创建并填充巨大的(例如 96 Go,72000行*72000列)数组,每个数组中都有来自数学公式的浮点数.该数组将在之后计算.
import itertools, operator, time, copy, os, sys
import numpy
from multiprocessing import Pool
def f2(x): # more complex mathematical formulas that change according to values in *i* and *x*
temp=[]
for i in combine:
temp.append(0.2*x[1]*i[1]/64.23)
return temp
def combinations_with_replacement_counts(n, r): #provide all combinations of r balls in n boxes
size = n + r - 1
for indices in itertools.combinations(range(size), n-1):
starts = [0] + [index+1 for index in indices]
stops = indices + (size,)
yield …Run Code Online (Sandbox Code Playgroud) 感谢您的所有教学答案和使用python库; o)
我将在Windows 7上启动并执行24个独立的python脚本.我希望一个脚本同时启动所有脚本...而不是统治它们(我不是Sauron)或等待它们的目的.我发现os.startfile()对此很有意思.但我没有成功地向那些24人发送争论.
coincoin1.py(要发布的24个脚本之一)
import sys
print "hello:",sys.argv
Run Code Online (Sandbox Code Playgroud)
Anti_Sauron_script.py(将一起启动24的那个)
sys.argv=["send","those","arguments"]
os.startfile("C:\\Users\\coincoin1.py")
Run Code Online (Sandbox Code Playgroud)
如何将参数发送到这些脚本并将它们一起启动?
我有一些状态通过转移概率链接(嵌入在马尔可夫链中的转换矩阵中).我想通过仅考虑足够高的概率来总结这个转移矩阵,它们允许从一个状态(〜节点)转到另一个状态(在我的转换矩阵中的第一个和最后一个).一个阈值,这样如果我只考虑更高的概率,我的转换矩阵永远不会允许从第一个状态(或节点)移动.
两个问题:
是否有一些众所周知的库(优先是python语言)实现这种方法?我的天真/经验/原型方法将是一个减少阈值的循环,然后检查我是否可以从第一个状态流到最后一个状态(距离矩阵中的最佳路径算法?).但这可能需要非常高的计算时间?
Example 1:
DistMatrix = [[ 'a', 'b', 'c', 'd'],
['a', 0, 0.3, 0.4, 0.1],
['b', 0.3, 0, 0.9, 0.2],
['c', 0.4, 0.9, 0, 0.7],
['d', 0.1, 0.2, 0.7, 0]]
states are a,b,c,d. I want to find the value (threshold) that allow to go from a to d (no matter if other states are walked)
Naive approach:
- first loop: threshold 0.9, I get rid of lesser probabilities: I can only connect c and b
- second …Run Code Online (Sandbox Code Playgroud) 我正在寻找在地图上绘制多个子图,每个子图都以一个地理位置(或绘图的一个坐标)为中心。节点本身没有位置(或者它们都属于一个城市),但每个子图对应一个本地情况。
我试图从/sf/answers/2071804661/ 中得到启发,在一个位置上绘制一个分层图,但没有成功
Run Code Online (Sandbox Code Playgroud)# -*- coding: utf-8 -*- import networkx as nx import pygraphviz import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap as Basemap G1 = nx.Graph() G1.add_edge('a', 'b', weight=0.6) G1.add_edge('a', 'c', weight=0.2) G1.add_edge('c', 'd', weight=0.1) G1.add_edge('c', 'e', weight=0.7) G1.add_edge('c', 'f', weight=0.9) G1.add_edge('a', 'd', weight=0.3) G2 = nx.Graph() G2.add_edge('a', 'b', weight=0.9) G2.add_edge('a', 'f', weight=0.5) G2.add_edge('c', 'd', weight=0.1) G2.add_edge('c', 'e', weight=0.4) G2.add_edge('c', 'f', weight=0.2) G2.add_edge('a', 'd', weight=0.1) edges = G.edges() weights = [G[u][v]['weight'] for u,v in edges] # …
我搜索使用seaborn和y轴损坏的小提琴图绘制catplot(因为我有一个作用在两个不同尺度上的因果过程:一个在[0,0.2]之间,第二个在[2,12]之间定量 y 变量)。
我从这个答案中了解到,还没有实现允许在seaborn中进行这种绘图的简单功能(还?) 所以我尝试了不同的方法,但没有成功,堆叠同一数据集但具有两种不同比例的两个图。
探索失败的尝试:
让我们使用标准数据集“exercise”,我尝试过:
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
exercise = sns.load_dataset("exercise")
f, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, sharey=True)
f = sns.catplot(x="time", y="pulse", hue="kind",data=exercise, kind="violin",ax=ax1)
f = sns.catplot(x="time", y="pulse", hue="kind",data=exercise, kind="violin",ax=ax2)
ax1.set_ylim(0, 6.5) # those limits are fake
ax2.set_ylim(13.5, 20)
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用facegrid但没有成功
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
exercise = sns.load_dataset("exercise")
g = sns.FacetGrid(exercise, col="kind",row="time")
g.map(sns.catplot, x="time", y="pulse", hue="kind",data=exercise, kind="violin") …Run Code Online (Sandbox Code Playgroud) 我有那些数据
a b c d e
alpha 5.51 0.60 -0.12 26.90 76284.53
beta 3.39 0.94 -0.17 -0.20 -0.20
gamma 7.98 3.34 -1.41 7.74 28394.93
delta 2.29 1.24 0.40 0.29 0.28
Run Code Online (Sandbox Code Playgroud)
我想做一个很好的可发布直方图作为这个 
但是在y轴上有一个中断,所以我们可以找出a,b,c,d和e的变化,这样数据就不会被e列中的极值压扁,而是使用隔行彩色条直方图:

我想在python(matplotlib,pandas,numpy/scipy)或mathematica ...或任何其他开放和免费的高级语言(R,scilab,...)中这样做.谢谢你的帮助.
编辑:通过pandas使用matplotlib允许使用左下角"hspace"的选项按钮调整两个子图之间的空间.
a= array([1,3,5,7,9])
b= array([2,4,6,8,10])
Run Code Online (Sandbox Code Playgroud)
我想混合一对数组,以便它们的序列逐个元素地插入示例:使用a和b,它应该导致
c= array([1,2,3,4,5,6,7,8,9,10])
Run Code Online (Sandbox Code Playgroud)
我需要在数千个序列上使用成对的长数组(超过一百个元素)来做到这一点.比每个阵列上的逐个元素酸洗更聪明的想法?谢谢
我想在 seaborn FacetGrid 图中格式化 y 轴标签,带有一些小数和/或添加一些文本。
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
#g.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: '{:,.2f}'.format(x) + 'K'))
#g.set(xticks=['a','try',0.5])
g.yaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: '{:,.2f}'.format(x) + 'K'))
plt.show()
Run Code Online (Sandbox Code Playgroud)
灵感来自如何将 seaborn/matplotlib 轴刻度标签从数字格式化为数千或数百万?(125,436 到 125.4K)
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
#g.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: '{:,.2f}'.format(x) + 'K'))
#g.set(xticks=['a','try',0.5])
g.yaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: '{:,.2f}'.format(x) + 'K'))
plt.show()
Run Code Online (Sandbox Code Playgroud)
它导致以下错误。
AttributeError: …
python ×11
matplotlib ×2
networkx ×2
numpy ×2
pandas ×2
plot ×2
seaborn ×2
analysis ×1
arrays ×1
facet-grid ×1
graph ×1
histogram ×1
matrix ×1
performance ×1
pygraphviz ×1
windows ×1