logo
down
shadow

Scilab: same legend size in multiple subplots


Scilab: same legend size in multiple subplots

By : Richy
Date : November 14 2020, 04:51 PM
Hope this helps I don't know either how to change directly the size of the legend: it seems to me, that it is always automatically calculated based on the length of the text. But there is a solution to get equally sized plots: you can set the size of the plot by the margins property of the axes. The second number adjusts the size of the "empty" space on the right hand side:
code :
x=1:0.1:6; //generate some data
y=[sin(x);sin(2*x)];

scf(0); clf(0);

subplot(2,1,1);
plot2d(x',y');
a=gca();  //get the current axes
a.margins=[0.05,0.2,0.125,0.125];  //set the margins
legend("y1","y2",-1,%T);

subplot(2,1,2);
plot2d(x',y');
a=gca();  //get the current axes
a.margins=[0.05,0.2,0.125,0.125];  //set the same margins to get equally sized plots
legend("y___1","y____2",-1,%T);


Share : facebook icon twitter icon
Adding a legend outside of multiple subplots with matplotlib

Adding a legend outside of multiple subplots with matplotlib


By : RHaw
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I ended up adding an extra subplot which I removed the frame and axis of, then plotted nothing to it and added a legend
code :
lastSubplot = plt.subplot(subcol,subrow,subcol*subrow)
lastSubplot.set_frame_on(False)
lastSubplot.get_xaxis().set_visible(False)
lastSubplot.get_yaxis().set_visible(False)
plt.plot(0, 0, marker='o', color='r', label = 'line1')
plt.plot(0, 0, marker='o', color='b', label = 'line2')
lastSubplot.legend(loc = 'lower right')
Scilab : Same colorbar for two subplots

Scilab : Same colorbar for two subplots


By : Timon
Date : March 29 2020, 07:55 AM
around this issue You may try to change the cdata_mapping from 'scaled' to 'direct' and scale the color matrix (which defines the color of each facet) according to the actual range used:
code :
x=[0:0.3:2*%pi];   //example data
[X,Y]=ndgrid(x,x);
Z1=sin(x')*cos(x);    //first data set
Z2=Z1./2;    //second dataset is half in amplitude

Zmin=min(min(Z1),min(Z2));    //Absolut minimum of all data sets
Zmax=max(max(Z1),max(Z2));    //Absolut maximum of all data sets
nc=100;   //number of colors in colormap

tabl=scf();
tabl.color_map=jetcolormap(nc);
subplot(1,2,1);
surf(X,Y,Z1);
h=gce();
cm=h.data.color;   //color matrix
h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1;   //scale color matrix & convert to color number
h.cdata_mapping="direct";   //change color mapping from 'scaled' to 'direct'
colorbar(Zmin,Zmax);

subplot(1,2,2);
surf(X,Y,Z2);
h=gce();
cm=h.data.color;   //color matrix
h.data.color=((cm-Zmin)./(Zmax-Zmin)).*(nc-1)+1;   //scale color matrix & convert to color number
h.cdata_mapping="direct";   //change color mapping from 'scaled' to 'direct'
colorbar(Zmin,Zmax);
Plot pandas dataframe with subplots (subplots=True): Place legend and use tight layout

Plot pandas dataframe with subplots (subplots=True): Place legend and use tight layout


By : ryanmat
Date : March 29 2020, 07:55 AM
I wish this help you
You can have all the legends in the same place, but you would have to create them in a separate step.
code :
# Plotting
df.plot(kind='line', subplots=True, grid=True, title="Sample Data (Unit)",
    layout=(4, 3), sharex=True, sharey=False, legend=False,    
    style=['r', 'r', 'r', 'g', 'g', 'g', 'b', 'b', 'b', 'r', 'r', 'r'],
    xticks=np.arange(0, len(df), 16))

[ax.legend(loc=1) for ax in plt.gcf().axes]
How to select legend handles and labels from specified subplots inside of subplots?

How to select legend handles and labels from specified subplots inside of subplots?


By : Jessica Bertrand All
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Rather than trying to call .get_legend_handles_labels on the array of subplots you want, you can just loop over the axes in that array, and append the handles and labels from those four subplots to a list.
For example:
code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

outerD = dict(nrows=1, ncols=2)
innerD = dict(nrows=2, ncols=2)
D = dict(inner=innerD, outer=outerD)

def initialize_dubsub(D, figsize=None):
    """ """
    fig = plt.figure(figsize=figsize)
    outerG = gridspec.GridSpec(D['outer']['nrows'], D['outer']['ncols'], wspace=0.2, hspace=0.2, width_ratios=[5, 5])
    axes = []
    for n in range(D['inner']['nrows']):
        inner = gridspec.GridSpecFromSubplotSpec(D['inner']['nrows'], D['inner']['ncols'], subplot_spec=outerG[n], wspace=0.25, hspace=0.3, width_ratios=[10, 10], height_ratios=[2, 2])
        for m in range(D['inner']['nrows']*D['inner']['ncols']):
            ax = plt.Subplot(fig, inner[m])
            ax.plot([], [], label='{}x{}'.format(n, m))
            ax.set_xticks([])
            ax.set_yticks([])
            axes.append(ax)
            fig.add_subplot(ax)
    handles, labels = [], []
    for ax in axes[:4]:
        handles_, labels_ = ax.get_legend_handles_labels()
        handles += handles_
        labels += labels_
    fig.legend(handles=handles, labels=labels, loc='lower center')
    #fig.legend(loc='lower center', ncol=4, mode='expand')
    plt.show()
    plt.close(fig)

initialize_dubsub(D)
Add colorbar as legend to matplotlib scatterplot (multiple subplots, multiple scatters)

Add colorbar as legend to matplotlib scatterplot (multiple subplots, multiple scatters)


By : Nikhil Francis
Date : March 29 2020, 07:55 AM
I wish did fix the issue. A colorbar needs a ScalarMappable as input. So if none of the things you create in your plot is suitable for that, you may create it yourself.
code :
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.cm import ScalarMappable

x = range(50)
scales = np.linspace(0, 2, 7)
locs = range(4)
cmap = plt.get_cmap("Spectral")
norm = plt.Normalize(scales.min(), scales.max())

fig, axes = plt.subplots(2,2, constrained_layout=True, sharey=True)

for s_plot, ax in enumerate(axes.flat):
    for scale in scales:
        y = np.random.normal(loc=locs[s_plot], scale=scale, size=50)
        sc = ax.scatter(x, y, c=[cmap(norm(scale))], s=5)
        ax.set_title("Mean = {:d}".format(locs[s_plot]))

sm =  ScalarMappable(norm=norm, cmap=cmap)
sm.set_array([])
cbar = fig.colorbar(sm, ax=axes[:,1])
cbar.ax.set_title("scale")

plt.show()
Related Posts Related Posts :
  • How to add extra root nodes for not well formed XML structure?
  • which Uncrustify setting replaces blank lines with indenting spaces?
  • mac OSX Lion Homebrew install curl (77)
  • In Project Euler 47, why is 2^2 considered a prime number distinct from 2?
  • browserstack requesting localhost:45691
  • What was the real reason why Google is chosing RenderScript instead of OpenCL?
  • Mandrill Inbound Email routing
  • Prevent checkElementIndex() Guava function from concatenating additional response to existing error message
  • Arduino and Raspberry Pi Serial communication + multiple variables
  • convert a 960 grid based site to responsive
  • Should it be possible to have more than one DocuSign account (DEMO) with the same email address?
  • Is it possible to limit ammount of concurrent builds in Travis-CI
  • Selecting languages with specific ISO code
  • Deprecated vs Unsupported SDK
  • Verifying ClearCase files have been labeled properly
  • What's the difference between "Bag of Words" and "Bag of features" in computer vision?
  • Is there a way to tell Serde to use a struct field as a map's key?
  • ld:framework not found sfml
  • nice, go-idiomatic way of using a shared map
  • IzPack ChmodInstallerListener.jar
  • Breaking down tasks of user stories between developer and QA
  • Dropwizard service not starting properly
  • How to override devise invitable actions
  • Coded UI. How can I change TimeOut in Find() method
  • Why when I click on the update button error TypeError: r is undefined happen?
  • Visio Component Diagram - Required Interface
  • Lucene: fast(er) to get docs in bulk?
  • can I use windows 8 font (Segoe UI)for my web app?
  • Using Flask Session in Gevent Socket-IO
  • Difference between recommended and suggested cookbooks
  • Dynamic Forms (Formsets) in Flask / WTForms?
  • Image Servlet doesn't want to show image in browser (FireFox, IE..) but in Eclipse browser works?
  • Logback - how to get each logger logging to a separate log file?
  • In Crystal Reports, how do I keep a row from printing if the value is null?
  • iOS 6 Audio multi-route - use external microphone AND internal speaker simultaneously
  • Adding Comments in JasperReports template (jrxml)
  • Servicestack mini profiler
  • Logging with Castle Windsor, the Logging Facility and log4net
  • Subscribe for instances list update in GCE autoscaled group
  • Generating a unique QR code for each Order in Woocommerce
  • libvirtError: internal error Cannot find suitable CPU model for given data
  • CKEditor changing content automatically
  • Pass double pointer in a struct to CUDA
  • Apache Camel for TCP based streamer
  • How to convert old CDC mainframe PRUs to bytes?
  • compilation on Blue Gene Q - ELF header
  • Set border of a jasper subreport having a title and a detail band
  • How to highlight tpl file?
  • cygwin: Starting cron as a service (access denied)
  • Can't access to the object after Importing from SVG
  • Hindi Font with DOMPDF in Codeigniter
  • XMLHttpRequest in a ContentScript from the Firefox SDK (Cross-Domain)
  • Adding javascript file or block to front page only drupal-7
  • No Emulator lists to deploy windows phone app
  • Redirection from component to view in joomla 2.5.8
  • What are possible solution for periodic folder sync between machines on linux?
  • Is there any status of review comments in gerrit
  • How can I permanently customize window size/buffer size of Command Prompt in Windows 7?
  • how to login in magento admin using coding
  • How to get all courses on moodle?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org