logo
down
shadow

Python / matplotlib: print to resolution and without white space / borders / margins


Python / matplotlib: print to resolution and without white space / borders / margins

Content Index :

Python / matplotlib: print to resolution and without white space / borders / margins
Tag : python , By : walshtp
Date : November 25 2020, 03:01 PM

Hope this helps I will neglect the point about more than 30000 points as this is nonsense for printing. So assuming a configuration as implied by the code of some 3000 points or so, you can calculate the figure size needed to show the plot with one point per printable point. You would also need to make sure that the linewidth is actually one dot wide.
import numpy as np
Fs = 512
# Create random signal
np.random.seed(1)
data = [np.random.uniform(-10000, 20000) for i in range(5*Fs)]

import matplotlib.pyplot as plt

dpi = 600
figheight = 4 # inch, some constant number

margin_left  = 1.0  # inch
margin_right = 0.4 # inch

figwidth = (len(data)/float(dpi)) + margin_left + margin_right # inch


plt.figure(figsize=(figwidth,figheight), dpi=dpi) 
plt.margins(x=0) # remove inner-axis padding of data
plt.subplots_adjust(left=margin_left/float(figwidth),
                    right=1.-margin_right/float(figwidth))
 # use 72/dpi for linewidth such that one point is one dot
plt.plot(data, color = "black", linewidth = 72./dpi)
plt.savefig("output.png", dpi="figure")
# note that show() may not make sense, 
# since it readjusts the figure size to maximum screen size
plt.show()

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Annoying white space in bar chart (matplotlib, Python)


Tag : python , By : Salikh
Date : March 29 2020, 07:55 AM
will be helpful for those in need It's probably a trivial question, but I am trying to plot a bar chart with matplotlib and with rotated text on the x axis. The code I'm using is shown below: , Try calling plt.xlim() with the number of bins, e.g.
plt.xlim([0,bins.size])
#make some data
N = 22
data = np.random.randint(1,10,N)
bin = np.arange(N)  
width = 1

#plot it
ax = plt.subplot(111)
ax.bar(bin, data, width, color='r')
plt.show()
#plot it
ax = plt.subplot(111)
ax.bar(bin, data, width, color='r')
plt.xlim([0,bin.size])
plt.show()

ax.fill() in matplotlib creates white margins


Tag : image , By : moss
Date : March 29 2020, 07:55 AM
around this issue Follow-up on my comment: The axis limits have changed. The image is in the rectangle between (0,0) and (500, 600). However the x- and y-lim are not exactly that; they range from (-100, -100) up to (500, 600). Just update the limits with ax.set_xlim([0, 500]) and ax.set_ylim([600, 0]) to remove the white frame around.
Note: if you also want to hide the ticks you easily do this with ax.set_xticks([]) and ax.set_yticks([]), or by setting the visibility of the ticks to False.

White space on top and bottom Python matplotlib plot


Tag : python , By : Steve
Date : March 29 2020, 07:55 AM
around this issue An option is to specify the bounding box of the table as the one to be used when saving the figure.
from matplotlib import pyplot as plt 

fig, ax = plt.subplots()

colums = ['col1', 'col2']
rows = ['row1', 'row2']
values = [[0, 1], [1, 0]]
table = ax.table(cellText=values, colLabels=colums, rowLabels=rows, loc='center')

ax.axis('off')

fig.canvas.draw()
bbox = table.get_window_extent(fig.canvas.get_renderer())
bbox_inches = bbox.transformed(fig.dpi_scale_trans.inverted())

fig.savefig('plop.png', bbox_inches=bbox_inches)

plt.show()
bbox = table.get_window_extent(fig.canvas.get_renderer())
bbox = bbox.from_extents(bbox.xmin-5, bbox.ymin-5, bbox.xmax+5, bbox.ymax+5)
bbox_inches = bbox.transformed(fig.dpi_scale_trans.inverted())

Why is there white space between the rows? I set all the margins and paddings to 0, but I can't get rid of the white spa


Tag : twitter-bootstrap , By : Xander
Date : March 29 2020, 07:55 AM
This might help you option 1: (CSS)
The border-collapse property sets whether table borders should collapse into a single border or be separated as in standard HTML. The border-spacing property sets the distance between the borders of adjacent cells.
table {
    ...
    border-spacing:0;
    border-collapse:collapse;
}
.table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid #dee2e6;
}
.table td, .table th {

    padding: .75rem;
    vertical-align: top;
    border-top: 1px solid #dee2e6;

}
.table thead th { 
    border-bottom: none !important; 
}
.table td, .table th { 
    border-top:none !important; 
}

Eliminate white space margins from Matplotlib graph in Power BI Service


Tag : python , By : user133834
Date : March 29 2020, 07:55 AM
This might help you plt.tight_layout() takes three arguments. You want to set them all to 0. Like plt.tight_layout(pad=0, w_pad=0, h_pad=0).
Related Posts Related QUESTIONS :
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com