标签: subplot

子图大小python

我现在面临的问题可以在图片中看到

这是左下图中的Y轴是大的,从-100到+600.有没有办法修改这个?我尝试了很多,但找不到它.

    # the random data
    x = np.random.randint(0,500,100000)
    y = np.random.randn(100000)



    fig = plt.figure(1, figsize=(5.5,5.5))

    from mpl_toolkits.axes_grid1 import make_axes_locatable

    # the scatter plot:
    axScatter = plt.subplot(111)
    axScatter.scatter(x, y)
    axScatter.set_aspect(1.)
    # create new axes on the right and on the top of the current axes
    # The first argument of the new_vertical(new_horizontal) method is
    # the height (width) of the axes to be created in inches.
    divider = make_axes_locatable(axScatter)
    axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
    axHisty = divider.append_axes("right", 1.2, pad=0.1, …
Run Code Online (Sandbox Code Playgroud)

python matplotlib subplot

3
推荐指数
1
解决办法
4529
查看次数

将轴最小值和最大值设置为粘滞

我有一个(3,4)子图,每个子图显示散点图.散点图的范围变化,因此我的一些图具有轴x(0-30)和y(0-8),但是一些具有x(18-22)和y(4-7).我将我的xlim设置为[0 30],将ylim设置为[0 8]但是我的轴设置为永远不会低于0,高于30等.

如何将我的轴设置为"粘贴"在(0,0)处为每个绘图的原点,并且"粘贴"为8表示Y,30表示X.

TIA提供任何帮助


更新每条评论答案:
以下代码仍有同样的问题

%% plot

for i = 1:num_bins;

h = zeros(ceil(num_bins),1);

h(i)=subplot(4,3,i);

plotmatrix(current_rpm,current_torque)

end

linkaxes(h,'xy');

axis([0 30 0 8]);
Run Code Online (Sandbox Code Playgroud)

matlab axes subplot

3
推荐指数
1
解决办法
1万
查看次数

当tight_layout失败时,如何减少水平子图间距?

我正在尝试使用subplot2grid在matplotlib中创建一个具有不同行和列跨度的子图的单个图形.

例如,以下代码:

import matplotlib.pyplot as plt
import numpy as n

fig = plt.figure()
ax1 = plt.subplot2grid((2, 5), (0, 0), rowspan=2, colspan=2)
ax2 = plt.subplot2grid((2, 5), (0, 2))
ax2_2 = plt.subplot2grid((2, 5), (0, 3))
ax2_3 = plt.subplot2grid((2, 5), (0, 4))
ax3 = plt.subplot2grid((2, 5), (1, 2), colspan=3) #, sharex=ax2)

xs = n.linspace(0, 2*n.pi, 100)
ax1.plot(xs, n.sin(xs))
ax2.plot(xs, n.cos(xs))
ax2_2.plot(xs, n.tan(xs))
ax2_3.plot(xs, n.sin(xs))
ax3.plot(xs, n.cos(xs))


ax2.set_xticklabels([])
ax2.set_yticklabels([])
ax2_2.set_xticklabels([])
ax2_2.set_yticklabels([])
ax2_3.set_xticklabels([])
ax2_3.set_yticklabels([])

# This comes from a separate attempt to make the ticks …
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib subplot

3
推荐指数
1
解决办法
3684
查看次数

如何使用Plotly带有折线图的堆积条形图?

https://plot.ly/python/bar-charts/#bar-chart-with-line-plot

我想使用plotly和iPython创建一个带有线条图的条形图,如上例所示.另一方面,我希望条形图是一个水平堆积条形图,如下面的例子中使用plotly和iPython.我该怎么做呢?

https://plot.ly/python/bar-charts/#colored-bar-chart

y_saving_yes = [1, 2, 4, 6, 7, 7]
y_saving_no = [10, 10, 10, 10, 10, 10]
y_net_worth = [93453, 81666, 69889, 78381, 141395, 92969]

x_saving = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']
x_net_worth = ['Premium', 'Spot Shadow', 'Slow Motion', 'Highlight Music','Extra Text', 'Top Play']

trace1 = Bar(
    x=y_saving,
    y=x_saving,
    marker=Marker(
        color='rgba(50, 171, 96, 0.6)',
        line=Line(
            color='rgba(50, 171, 96, 1.0)',
            width=1,
        ),
    ),
    name='Highlight Properties',
    orientation='h',
)

trace2 = Bar(
    x=y_saving,
    y=x_saving,
    marker=Marker(
        color='rgba(50, …
Run Code Online (Sandbox Code Playgroud)

linegraph ipython bar-chart subplot plotly

3
推荐指数
1
解决办法
1975
查看次数

Matplotlib:字幕位置错误,图例不可见

我有五个列表,我打算在两个单独的子图中绘制.在子图1中我想要列表1,2,3和4; 在子图2中我想要列表4和5.这些是列表和event_index用于设置x label.

event_index=['event 1','event 2','event 3','event 4','event 5','event 6','event 7','event 8','event 9','event 10']
list1 = [0.7,0.8,0.8,0.9,0.8,0.7,0.6,0.9,1.0,0.9]
list2 = [0.2,0.3,0.1,0.0,0.2,0.1,0.3,0.1,0.2,0.1]
list3 = [0.4,0.6,0.4,0.5,0.4,0.5,0.6,0.4,0.5,0.4]
list4 = [78,87,77,65,89,98,74,94,85,73]
list5 = [16,44,14,55,34,36,76,54,43,32]
Run Code Online (Sandbox Code Playgroud)

为了生成两个子图,我使用以下代码:

fig = plt.figure() #Creates a new figure
ax1 = fig.add_subplot(211) #First subplot: list 1,2,3, and 4
ax2 = ax1.twinx() #Creates a twin y-axis for plotting the values of list 4
line1 = ax1.plot(list1,'bo-',label='list1') #Plotting list1
line2 = ax1.plot(list2,'go-',label='list2') #Plotting list2
line3 = ax1.plot(list3,'ro-',label='list3') #Plotting list3
line4 …
Run Code Online (Sandbox Code Playgroud)

python matplotlib subtitle subplot

3
推荐指数
1
解决办法
1万
查看次数

如何在 Julia Plots 中创建任意数量的子图

我想使用 Breloff 的 Julia Plots从多维数组中制作一组子。这个 plot 函数接受一个 varargs 输入并将它们变成子图,但我似乎无法正确输入我的数组,并且可能忽略了一些简单的东西。例如使用数组a

a = randn(5,5,8)
a = a.-mean(a)
a = a./maximum(extrema(a))
Run Code Online (Sandbox Code Playgroud)

如果我想将一些 5x5 切片绘制为热图,我可以这样做:

plot(heatmap(a[:,:,1], aspect_ratio=:equal, clims=(-1,1), title=string(1)), 
heatmap(a[:,:,2], aspect_ratio=:equal, clims=(-1,1), title=string(2)),
heatmap(a[:,:,3], aspect_ratio=:equal, clims=(-1,1), title=string(3)))
Run Code Online (Sandbox Code Playgroud)

它产生:

3个热图数组

但是如果我想完成所有八个(或我的目标是一个可变数字),我不能让它与循环或 splat 一起工作。我尝试后者创建一个元组,但出现错误:

plot(tuple([heatmap(a[:,:,i], aspect_ratio=:equal, clims=(-1,1)) for i in 1:8]...))

LoadError: MethodError: Cannot `convert` an object of type String to an object of type MethodError
This may have arisen from a call to the constructor MethodError(...),
since type constructors fall back …
Run Code Online (Sandbox Code Playgroud)

heatmap subplot julia plots.jl

3
推荐指数
1
解决办法
2083
查看次数

如何使用matplotlib将inset_axes添加到子图

我正在尝试在matplotlib中绘制多个子图,每个子图应具有插入轴。我可以使用添加的插入轴使代码示例适用于单个轴mpl_toolkits.axes_grid.inset_locator.inset_axes(),并且可以在没有插入轴的情况下很好地绘制子图,但是当尝试在循环中对子图进行相同操作时,我进入TypeError: 'AxesHostAxes' object is not callable 了第二个子图。当number_of_plotsis == 1而不是> 1 时应该工作似乎有点奇怪。我应该怎么做,还是一个bug?(matplotlib.__version__是“ 1.5.1”)

from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid.inset_locator import inset_axes
import numpy as np
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
n_row, n_col = 4, 4
fig = plt.figure(1,(10,10))
#number_of_plots = 1 Works!
number_of_plots = n_row * n_col # Does not work!
for idx in range(number_of_plots):
    ax = fig.add_subplot(n_row, n_col, idx + 1)
    ax.plot(x, y)
    inset_axes = …
Run Code Online (Sandbox Code Playgroud)

python matplotlib subplot

3
推荐指数
1
解决办法
1131
查看次数

Matplotlib - 沿同一轴的不同刻度标签对齐

我有一个带有很多子图的图形,因此轴的最后一个刻度标签写在下一个刻度标签的第一个刻度标签上。 请参阅此处的示例

由于我想在设置子图时保持子图之间的间距,因此我希望根据刻度进行不同的对齐,因为它可以通过以下方式生成:

    plt.xticks([0], ha = 'left')
    plt.xticks([0.2,0.4], ha = 'center')
    plt.xticks([0.6], ha = 'right')
Run Code Online (Sandbox Code Playgroud)

使用它,图中只显示了 xticks 的最后一次调用。换句话说,这个想法是对齐第一个和最后一个刻度标签,使它们留在子图中。

希望我很清楚!

有任何想法吗 ?

matplotlib subplot axis-labels

3
推荐指数
1
解决办法
1944
查看次数

在 matplotlib 中 .imshow() 之后保存子图

这是我的可视化代码:

f, ax = plt.subplots(1, 2)
for i, img in enumerate([img1, img2]):    
    grads = # my visualization codes
# visualize grads as heatmap
ax[i].imshow(grads, cmap='jet')
Run Code Online (Sandbox Code Playgroud)

我怎么能保存imshow这里显示的内容?任何意见是极大的赞赏!

python visualization matplotlib subplot

3
推荐指数
1
解决办法
4221
查看次数

ValueError:为 plotly.graph_objs.Pie 类型的对象指定的属性无效:'xaxis'

我试图在 2 个不同的轴上绘制 2 个不同的 Plotly 饼图。这是我的代码:

fig = tools.make_subplots(rows=1, cols=2)

monday_freq = meta_df['monday_is_day_off'].value_counts()
tuesday_freq = meta_df['tuesday_is_day_off'].value_counts()

trace1 = go.Pie(labels=list(monday_freq.keys()), 
values=list(monday_freq.values), hole=0.7, hoverinfo='label+percent')
trace2 = go.Pie(labels=list(tuesday_freq.keys()), 
values=list(tuesday_freq.values), hole=0.7, hoverinfo='label+percent')

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)

iplot(fig)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到以下错误:

ValueError: Invalid property specified for object of type plotly.graph_objs.Pie: 'xaxis'
Run Code Online (Sandbox Code Playgroud)

我一直在网上寻找解决方案,但无济于事。

python plot visualization subplot plotly

3
推荐指数
1
解决办法
9644
查看次数