Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 913547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:34:46+00:00 2026-05-15T17:34:46+00:00

I’m trying to use matplotlib to prepare some figures for publication. In order to

  • 0

I’m trying to use matplotlib to prepare some figures for publication. In order to make the font sizes match the text of the manuscript I’m trying to create the figure in the final size to begin with, so that I avoid scaling the figure when inserting it into the manuscript.

The problem I’m having is that as the figure is then pretty small, I can scale font sizes, axis sizes, line widths etc., but what I’ve been unable to figure out is how to scale dashed or dotted lines, as well as the thickness of the legend border box. For a simplified and somewhat exaggerated example, consider


#!/usr/bin/python

small = True


from matplotlib import use
use('pdf')

from matplotlib import rc
rc('ps', usedistiller='xpdf')
rc('text', usetex=True)

if small:
    figsize = (1.0, 0.5)
    rc('font', size=2)
    rc('axes', labelsize=2, linewidth=0.2)
    rc('legend', fontsize=2, handlelength=10)
    rc('xtick', labelsize=2)
    rc('ytick', labelsize=2)
    rc('lines', lw=0.2, mew=0.2)
    rc('grid', linewidth=0.2)
else:
    figsize = (8,8)

import numpy as np

x = np.arange(0, 10, 0.001)
y = np.sin(x)

import matplotlib.pyplot as plt
f = plt.figure(figsize=figsize)
a = f.add_subplot(111)
a.plot(x, y, '--', label='foo bar')
a.legend()
f.savefig('mplt.pdf')

If you change the first executable line to small = False you can see how it should look in “normal” size. Compared to the normal size, the small plot suffers from a legend box with too thick borders, and the dashed line is too coarse, i.e. too long dashes and too long distance between the dashes.

So my question is, is there a way to fix these two problems?

The matplotlib version I’m using is 0.99.1.2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:34:47+00:00Added an answer on May 15, 2026 at 5:34 pm

    To adjust the dashes, use

    a.plot(x, y, '--', label='foo bar', dashes=(2,2))
    

    and the legend box line width,

    lg = a.legend()
    fr = lg.get_frame()
    fr.set_lw(0.2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.