logo
down
shadow

Creating a figure with plots, sliders and other widgets arranged with a gridspec layout


Creating a figure with plots, sliders and other widgets arranged with a gridspec layout

By : user2185616
Date : November 22 2020, 04:01 AM
Hope this helps Some issues:
plot doesn't have any xlim argument. There is one grid too much in the code Widgets need to live inside axes The first index of a grid is the rows, not the columns.
code :
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.widgets import Slider

# Half width of the graph x-axis
x_axis = 4*np.pi
# x_axis offset
x_offset = 0
# Half height of the graph y-axis
y_axis = 8
# y_axis offset
y_offset = -1

fig = plt.figure()

mainGrid = gridspec.GridSpec(2, 1)
ax = plt.subplot(mainGrid[0, :])
ax.set(xlim=(-x_axis-x_offset, x_axis-x_offset), ylim=(-y_axis-y_offset, y_axis-y_offset))
controlCell = mainGrid[1, :]

sliderCount = 7
sliderGrid = gridspec.GridSpecFromSubplotSpec(sliderCount, 1, controlCell)
sliders = []
for i in range(0, sliderCount):
    sliderax = plt.subplot(sliderGrid[i, 0])
    slider = Slider(sliderax, "Test {}".format(i), 0.1, 8.0, valinit=2, valstep=0.01)
    sliders.append(slider)

x_data = np.linspace(-x_axis-x_offset, x_axis-x_offset, 512)
y_data = [x for x in x_data]

line = ax.plot([], [])[0]
line.set_data(x_data, y_data)

plt.show()


Share : facebook icon twitter icon
How to replace previous plots in a matplotlib figure with new plots or grid of plots?

How to replace previous plots in a matplotlib figure with new plots or grid of plots?


By : ipans
Date : March 29 2020, 07:55 AM
it fixes the issue This doesn't looks like a very standard way of doing tkinter. At least it's not very clear to me what you're trying to achieve. You have the following line in your dosomething:
code :
test1=Test1(windows, data, axes)
def dosomething():
    try: 
        self.canvas.get_tk_widget().destroy()
    except:
        pass        
    fig = Figure(figsize=(12, 4))
    axes = fig.add_subplot(111)
    self.canvas = FigureCanvasTkAgg(fig, master=windows)
    self.canvas.get_tk_widget().pack()
    data=np.arange(100)  # not sure what this is for

def dosomethingelse():
    try: 
        self.canvas.get_tk_widget().destroy()
    except:
        pass 
    fig = Figure(figsize=(12, 4))
    fig.plot(np.arange(100)+10*(np.random.rand(100)-0.5),'-r')
    self.canvas = FigureCanvasTkAgg(fig, master=windows)
    self.canvas.get_tk_widget().pack()        
Creating normalized gaussian graphs arranged in triangular subplots using gridspec

Creating normalized gaussian graphs arranged in triangular subplots using gridspec


By : Maxi Sc
Date : March 29 2020, 07:55 AM
hop of those help? Right now you have a confusing way of setting up the plots of the Gaussians. Calling plt.plot draws the plot on the currently active axes, which is why they all show up on the same graph. You should try changing your code for plotting the diagonal elements to something like the following:
code :
for i, (mu, sig_gauss) in enumerate(sig_mean):
        ax = plt.subplot(gs1[i,i])
        ax.plot(gaussian(np.linspace(-3, 3, 120), mu, sig_gauss))
        ax.grid()
Thumbnail plots with matplotlib GridSpec

Thumbnail plots with matplotlib GridSpec


By : Allen Lyu
Date : March 29 2020, 07:55 AM
it should still fix some issue From the function definition add_inset_to_axis(figure, axis, rect) it seems that the second argument is actually meant to be a matplotlib.axes instance.
So instead of giving grid_cell as an argument, one should probably use axis
code :
inset = add_inset_to_axis(fig, axis, (0.675, 0.82, 0.3, 0.15))
Matplotlib Gridspec - Plots and images on A4 Page

Matplotlib Gridspec - Plots and images on A4 Page


By : Eli Robbins
Date : March 29 2020, 07:55 AM
will help you So I changed the layout a little, but the solution was to set the figsize to that of A4 paper and adjusting the height ratios of gs. Also fig.set_size_inches takes width as first argument, then height.
code :
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

mpl.use('pdf')

img = np.random.standard_normal((20,20))
data = np.random.standard_normal((10000,2))
theta = [1,2]
description = 'Size: %s, #Samples: %s, Computation Time: %ss'%(25, 13, int(12.5))

title_fontsize = 'x-small'
fig = plt.figure(dpi=300, tight_layout=True)
fig.set_size_inches(8.27, 11.69, forward=True)

plt.figtext(0.02, .99, description, fontsize = 'small')

ax = np.zeros(9, dtype=object)
gs = fig.add_gridspec(5, 3, height_ratios=[3,2,3,2,2])
ax[0] = fig.add_subplot(gs[0, 0])
ax[1] = fig.add_subplot(gs[0, 1])
ax[2] = fig.add_subplot(gs[0, 2])
ax[3] = fig.add_subplot(gs[1, :])
ax[4] = fig.add_subplot(gs[2, 0])
ax[5] = fig.add_subplot(gs[2, 1])
ax[6] = fig.add_subplot(gs[2, 2])
ax[7] = fig.add_subplot(gs[3, :])
ax[8] = fig.add_subplot(gs[4, :])

ax[0].imshow(img)
ax[0].set_title('Slice through Covariance Operator', fontsize = title_fontsize)

ax[1].imshow(img)
ax[1].set_title('Last Sample', fontsize = title_fontsize)

ax[2].imshow(img)
ax[2].set_title('Truth', fontsize = title_fontsize)

for i, d in enumerate(data.T):
    ax[3].plot(d, label = '%s°'%int(theta[i]))

ax[3].legend(loc='upper right')
ax[3].set_title('Measurement (Sinogram)', fontsize = title_fontsize)

ax[4].imshow(img)
ax[4].set_title('MCMC Reconstruction (Sample Mean)', fontsize = title_fontsize)

ax[5].imshow(img)
ax[5].set_title('MCMC Sample Variance', fontsize = title_fontsize)

ax[6].imshow(img)
ax[6].set_title('FBP Reconstruction', fontsize = title_fontsize)

ax[7].plot(data)
ax[7].set_title('Heightscale', fontsize = title_fontsize)

ax[8].plot([b[0] for b in data], label='Layer 1')
ax[8].plot([b[1] for b in data], label='Layer 0')
ax[8].legend(loc='upper right')
ax[8].set_title('Jump Size', fontsize = title_fontsize)
for x in ax.flat:
    for tick in x.xaxis.get_major_ticks():
        tick.label.set_fontsize('xx-small')
    for tick in x.yaxis.get_major_ticks():
        tick.label.set_fontsize('xx-small')

plt.savefig('test.pdf')
"'module' object has no attribute 'Gridspec'" despite calling help(gridspec) revealing the Gridspec class

"'module' object has no attribute 'Gridspec'" despite calling help(gridspec) revealing the Gridspec class


By : Bigmo
Date : March 29 2020, 07:55 AM
I wish this help you You meant to type g = gs.GridSpec(1,1). The "s" in "Spec" is capitalized.
Related Posts Related Posts :
  • Pythonic way set variables if none in __init__
  • Python remove duplicate entries from list within a list
  • I'm trying to perform certain pattern matching using python's re module
  • Format Google Calendar Event Date
  • How to remove apostrophe's when writing to csv file in Python
  • How to graph the second derivatives of coupled non-linear second order ODEs in Python?
  • Full gradient descent in keras
  • How to manually calculate AUC of the ROC?
  • Python http.server command gives "Syntax Error"
  • How to groupby and sum if the cell value of certain columns fit specific conditions
  • Batch file not closed after being created and written to by Python?
  • Adding an extra in column into 2D numpy array python
  • Scraping content using pyppeteer in association with asyncio
  • Rearrange rows of Dataframe alternatively
  • Function not returning value due to errors in if else logic
  • Value Error in Python while calling a function
  • Is it possible to check if a function is decorated inside another function?
  • How to change "style property" in pygtk2
  • how to create new dataframe out of columns after resampling?
  • Why doesn't this Python code work? It returns no output
  • Python - Split multiple columns into multiple rows
  • Pyinstaller 3.4 Not Working on Windows 10 with Python 2.7
  • inputing numpy array images into pytorch neural net
  • Creating a Dataframe of Proportions
  • Scrapy with dynamic captcha
  • In python, how do I get urllib to recognize multiple lines in a string as separate URLs?
  • Add prefix and suffix to each element of a nested list
  • Generate string set from csv file in Python
  • Custom usage message for many-valued argument
  • Python Class, how to skip a wrong entry and proceed to next entry
  • Numpy efficient way to parse array of string
  • Kivy , Python: Update Label on_file_drop
  • What does it mean if a deeper conv layer converges first?
  • Selecting User in client.send_message() from arg list
  • python slicing multi levels list of dict using list comprehension
  • Value Error problem with multicell Dimensions must be equal, but are 20 and 13
  • How to print a board with coordinates?
  • Keras LSTM shape doesn't contain length of sequence
  • Boxplot with Pandas in Python
  • How can I rename a PySpark dataframe column by index? (handle duplicated column names)
  • How to calculate hash of a python class object
  • Using ideas from HashEmbeddings with sklearn's HashingVectorizer
  • keycloak.exceptions.KeycloakGetError: 404: b'' using Python 3.7
  • How to modify a column in a SQLite3?
  • VS Integration Services: flat file source to OLE DB destination - detect new data columns in file, add columns to table,
  • Customize xticks in matplotlib plot
  • How can I show the image in a labelframe which is inserted through askopenfilename?
  • Boxplot with distibution size histogram on top (and median regression)
  • Fit differential equation with scipy
  • ModuleNotFoundError: Correct setup
  • How to pass rendered plot to a html file through render_template?
  • Create flat ndarray from DataFrame column containing arrays
  • Bring radial axes labels in front of lines of polar plot matplotlib
  • Python3: Unable to split word from parsed data
  • Using Python to login to a website and web scrape
  • Customise shift in matplotlib offset
  • Combining and Reshaping rows and columns of 2 dataframes in R or Python
  • Regex condition after and before a known phrase
  • subplots based on records of two different pandas DataFrames ( with same structure) using Seaborn or Matplotlib
  • find numpy array in other numpy array
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org